{$A+,B-,C+,D+,E-,F-,G+,H+,I+,J+,K-,L+,M-,N+,O+,P+,Q+,R+,S+,T-,U-,V+,W-,X+,Y+,Z1}
{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $00100000}
{$IMAGEBASE $00400000}
{$APPTYPE CONSOLE}

{All this dirty code written by avm.}
uses Math;
const maxV  = 26*26*26;
      maxN  = 100000;
  file_name = 'counts';
type
PEdge = ^TEdge;
TEdge = record
  v:integer;
  next:PEdge;
  end;
PEdgeArray = array[0..maxV-1] of PEdge;
TIntegerArray = array[0..maxV-1] of integer;
var n:integer;
    s:string;
    i1,i2,v:array[0..maxV-1] of boolean;
    ver,col,b:TIntegerArray;
    d:array[0..maxV-1] of integer;
    e,e2:PEdgeArray;
  buf:array[1..2*maxN] of TEdge;

 //q,sum,t_in,t_out,total:integer;

function hieroglyph2int(s:string) : integer;
var i : integer;
begin
Result := 0;
for i:=1 to 3 do
  begin
  ASSERT(s[i] in ['A'..'Z']);
  Result := Result * 26 + (ord(s[i]) - 65);
  end;
end;

procedure visit(const e:PEdgeArray;var a,b:TIntegerArray;var m:integer;i,color:integer);
var p:PEdge;
begin
if v[i] then exit;
v[i] := true;
p := e[i];
while p<>nil do
  begin
  visit(e,a,b,m,p^.v,color);
  p := p^.next;
  end;
b[i] := color;
a[m] := i;
inc(m);
end;

procedure Test;
var i,j,k,l,m,cur,nc,nc2,c1,c2:integer;
    p:pEdge;
begin
Readln(n);
Assert(n <= MaxN);
cur := 0;
for i:=0 to maxV-1 do
  begin
  e[i] := nil;
  e2[i] := nil;
  d[i] := 0;
  end;
for k:=1 to n do
  begin
  Readln(s);
  l := Length(s);
  Assert((l mod 3) = 0);
  Assert(l >= 3);
  Assert(l <= 30);
  j := hieroglyph2int(Copy(s,1,3));
  i := hieroglyph2int(Copy(s,l-2,3));
  inc(d[i]);inc(d[j]);
  //add edge(i,j)
  inc(cur);
  p := @buf[cur];
  p^.next := e[i];
  p^.v := j;
  e[i] := p;
  //add edge(j,i)
  inc(cur);
  p := @buf[cur];
  p^.next := e2[j];
  p^.v := i;
  e2[j] := p;
  end;
if n = 1 then
  begin
  writeln(0);
  exit;
  end;
for i:=0 to maxV-1 do v[i] := d[i] = 0;
nc := 0;
for i:=0 to maxV-1 do
  if not v[i] then
    begin
    visit(e,ver,b,nc,i,0);
    end;
for i:=0 to maxV-1 do
  begin
  v[i] := d[i] = 0;
  col[i] := -1;
  i1[i] := false;
  i2[i] := false;
  end;
m := 0;
nc2 := 0;
for i:=nc-1 downto 0 do
  begin
  if not v[ver[i]] then
    begin
    visit(e2,b,col,nc2,ver[i],m);
    inc(m);
    {
    col[ver[i]] := nc2;
    inc(nc2);
    }
    end;
  end;
if m = 1 then
  begin
  writeln('0');
  exit;
  end;
{for i:=0 to maxV-1 do col[b[i]] := i;}
for i:=0 to maxV-1 do
  begin
  p := e[i];
  while p<>nil do
    begin
    if col[i] <> col[p^.v] then
      begin
      i1[col[i]] := true;
      i2[col[p^.v]] := true;
      end;
    p := p^.next;
    end;
  end;
c1 := 0;
c2 := 0;
for i:=0 to m-1 do
  begin
  if not i1[i] then inc(c1);
  if not i2[i] then inc(c2);
  end;
writeln(Max(c1,c2));
end;

begin
Assign(input,file_name + '.in');Reset(input);
Assign(output,file_name + '.out');Rewrite(output);
Test;
end.
