import java.io.PrintStream;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Random;
import java.util.Scanner;

/**
 * Solution to Longest Common Substring
 * 
 * @author vanb
 */
public class lcs_vanb
{
    /** Input. */
    private static Scanner sc;
    
    /** Output. */
    private static PrintStream ps;
    
    /**
     * Do it!
     */
    private void doit()
    {
        int n = sc.nextInt();
        
        // Create a list of candidates from the first permutation, ordered by size
        String first = sc.next(); 
        int k = first.length();
        ArrayDeque<String> candidates = new ArrayDeque<String>(k*(k-1)/2);        
        for( int len=k; len>0; --len ) for( int start=0; start+len<=k; start++ )
        {
            candidates.add( first.substring( start, start+len ) );
        }
                
        // Eliminate candidates that don't fit subsequent permutations
        for( int i=1; i<n; i++ )
        {
            String permutation = sc.next();
            Iterator<String> it = candidates.iterator();
            while( it.hasNext() )
            {
                String candidate = it.next();
                if( !permutation.contains( candidate ) ) it.remove();
            }
        }
        
        ps.println( candidates.size()==0 ? 0 : candidates.getFirst().length() );
    }
        
    /**
     * Main.
     * 
     * @param args unused
     * @throws Exception
     */
    public static void main( String[] args ) throws Exception
    {
        sc = new Scanner( System.in );
        ps = System.out;
        
        new lcs_vanb().doit();       
    }

}
