#include <iostream>
#include <string.h>
using namespace std;
struct telefone{
char digito[200];
};
int main(void){
long int i = 0, N = 0;
int soma = 0, j = 0;
cin >> N;
while(!cin.eof()){
struct telefone tel[N];
for(i=0; i<N; i++){
cin >> tel[i].digito;
}
int tamanho = strlen(tel[0].digito);
for(i = 0; i < N - 1 ; i++){
for(j=0; j<tamanho; j++){
if (tel[i].digito[j] == tel[i+1].digito[j])
soma++;
else break;
}
}
cout << soma << endl;
soma = 0;
cin >> N;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJ1Y3QgdGVsZWZvbmV7CiAgICBjaGFyIGRpZ2l0b1syMDBdOwp9OwoKaW50IG1haW4odm9pZCl7CgogICAgbG9uZyBpbnQgaSA9IDAsIE4gPSAwOwogICAgaW50IHNvbWEgPSAwLCBqID0gMDsKCiAgICAgICAgY2luID4+IE47CgogICAgd2hpbGUoIWNpbi5lb2YoKSl7CiAgICBzdHJ1Y3QgdGVsZWZvbmUgdGVsW05dOwoKICAgIGZvcihpPTA7IGk8TjsgaSsrKXsKICAgICAgICBjaW4gPj4gdGVsW2ldLmRpZ2l0bzsKICAgIH0KICAgIGludCB0YW1hbmhvID0gc3RybGVuKHRlbFswXS5kaWdpdG8pOwoKICAgIGZvcihpID0gMDsgaSA8IE4gLSAxIDsgaSsrKXsKICAgICAgICBmb3Ioaj0wOyBqPHRhbWFuaG87IGorKyl7CiAgICAgICAgICAgICAgICBpZiAodGVsW2ldLmRpZ2l0b1tqXSA9PSB0ZWxbaSsxXS5kaWdpdG9bal0pCiAgICAgICAgICAgICAgICAgICAgc29tYSsrOwogICAgICAgICAgICAgICAgZWxzZSBicmVhazsKICAgICAgICAgICAgfQogICAgfQogICAgY291dCA8PCBzb21hIDw8IGVuZGw7CiAgICBzb21hID0gMDsKICAgIGNpbiA+PiBOOwoKICAgIH0KfQ==