import sys;

a = [raw_input() for i in xrange(input())];

pos = 0;
while len(set(x[0:pos] for x in a)) < 2:
    pos += 1;
print pos - 1;





import sys;

a = [raw_input() for i in xrange(input())];

pos = 0;
while True:
    ok = True;
    c = a[0][pos];
    for i in xrange(len(a)):
        if a[i][pos] != c:
            ok = False;
    if not ok :
        break;
    pos += 1;
print pos;

