import java.io.*;
import java.util.*;


public class counts_vv extends Thread {

  String FILE_NAME = "counts";
  Scanner in;
  PrintWriter out;

  int[] d1;
  int[] d2;
  int[][] e1;
  int[][] e2;
  int cc;
  int[] col;
  int[] ver;
  boolean[] gone;
  boolean[] g;

  public void poisk(int v){
    gone[v] = true;
    for(int i=0;i<d1[v];i++)
      if (!gone[e1[v][i]]){
        poisk(e1[v][i]);
      }
    ver[cc] = v;
    cc++;
  }

  public void ksiop(int v){
    gone[v] = true;
    for(int i=0;i<d2[v];i++)
      if (!gone[e2[v][i]]){
        ksiop(e2[v][i]);
      }
    col[v] = cc;
  }

  public void run() {
    try
    {
      in = new Scanner(new File(FILE_NAME+".in"));
      out = new PrintWriter(new BufferedWriter(new FileWriter(new File(FILE_NAME+".out"))));
    }
    catch (Exception e)
    {
      assert (false);
    }
    int n = in.nextInt();
    if (n==1){
      out.println("0");
      out.close();
      return;
    }
    int[] x = new int[n];
    int[] y = new int[n];
    col = new int[26*26*26];
    d1 = new int[26*26*26];
    d2 = new int[26*26*26];
    e1 = new int[26*26*26][];
    e2 = new int[26*26*26][];
    col = new int[26*26*26];
    ver = new int[26*26*26];
    g =  new boolean[26*26*26];
    
    for(int i=0;i<n;i++){
      String a = in.next();
      int k = a.length();
      x[i] = (a.charAt(0)-'A')*26*26+(a.charAt(1)-'A')*26+a.charAt(2)-'A';
      y[i] = (a.charAt(k-3)-'A')*26*26+(a.charAt(k-2)-'A')*26+a.charAt(k-1)-'A';
      d1[x[i]]++;
      d2[y[i]]++;
      g[x[i]] = true;
      g[y[i]] = true;
    }

    int m = 26*26*26;
    for(int i=0;i<m;i++){
      e1[i] = new int[d1[i]];
      e2[i] = new int[d2[i]];
    }
    int[] q1 = new int[m];
    int[] q2 = new int[m];
    gone = new boolean[m];

    for(int i=0;i<n;i++){
      e1[x[i]][q1[x[i]]] = y[i]; q1[x[i]]++;
      e2[y[i]][q2[y[i]]] = x[i]; q2[y[i]]++;
    }

    cc = 0;
    for(int i=0;i<m;i++)
      if (!gone[i] && g[i]) poisk(i);
    int qc = cc;
    cc = 0;
    Arrays.fill(gone,false);
    for(int i=qc-1;i>=0;i--){
      if (!gone[ver[i]]){
        ksiop(ver[i]);
        cc++;
      }
    }
    if (cc == 1){
      out.println(0);
      out.close();
      return;
    }
    boolean[] i1 = new boolean[cc];
    boolean[] i2 = new boolean[cc];
    for(int i=0;i<n;i++){
      if (col[x[i]]!=col[y[i]]){
        i1[col[x[i]]] = true;
        i2[col[y[i]]] = true;
      }
    }
    int j1 = 0;
    int j2 = 0;
    for(int i=0;i<cc;i++){
      if (!i1[i]) j1++;
      if (!i2[i]) j2++;
    }
    out.println(Math.max(j1,j2));
    out.close();
  }

  public static void main(String[] args) throws Exception{
    Thread a = new counts_vv();
    a.start();
  }
}
