#include
#include
#include
#include
using namespace std;
int m ,k;
int n;
long long x;
class node{
public:
node *a, *b;
long long bitmask;
node(){
a = NULL;
b = NULL;
bitmask = 0;
}
};
int ret;
string curr;
void rek(int at, int depth, node *tmp){
tmp -> bitmask |= x;
int popcount = __builtin_popcount(tmp -> bitmask);
if(popcount == n && depth > ret){
ret = depth;
}
if(at == (int)curr.size() || depth > 60){
return;
}
if(curr[at] == 'a'){
if(tmp -> a == NULL){
tmp -> a = new node();
}
rek(at + 1, depth + 1, tmp -> a);
}
else{
if(tmp -> b == NULL){
tmp -> b = new node();
}
rek(at + 1, depth + 1, tmp -> b);
}
}
int main(int argc, const char * argv[]) {
ios_base::sync_with_stdio(false);
cin >> n;
string s[6];
node *root = new node();
for(int i =0; i < n; i ++){
cin >> s[i];
}
for(int i =0; i < n; i ++){
curr = s[i];
x = (1 << i);
for(int j =0; j < s[i].size(); j ++){
rek(j, 0, root);
}
}
cout << ret << endl;
return 0;
}