9
lfpgbnlzyn
c
s
w
r
m
q
y
yinfblfcdhidphyfvgkxyuwomahiibbhnigdslsguhjkplibnhhrshtekwgefxeugyyyyy
 6
u
p
m
z
v
vv
 4
qe
nd
iqryhukieskfvaeettersinksrmazelxtgvartuz
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
 6
nf
ysvchtjkfgsbyfzxjaykey
advqnf
wl
pi
ppppfvvmaebvhkoagppppp
 3
j
k
kkailgwqnxtdsttkkkkkkk
 4
o
yhnx
e
ennn
 10
j
dyfu
udzj
wwow
xtnw
f
c
q
o
gggg
 6
w
g
c
j
y
f
 4
r
o
w
wwwwwwwwww
 2
zxwp
ppppctfisvflhtjggg
 5
m
g
u
t
tttt
 2
n
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
 3
lt
en
eeeeeeeeee
 4
vr
hp
l
llbn

7 5 541 10 10 4 4 1 21 5 9 93 21 3
#include <bits/stdc++.h>
using namespace std;
bool all_str(string s, char x) {
  for (char a : s) {
    if (a != x) {
      return false;
    }
  }
  return true;
}
int len_pref(string s, char x) {
  int c = 0;
  for (char a : s) {
    if (a == x) {
      c++;
    } else {
      break;
    }
  }
  return c;
}
int len_suff(string s, char x) {
  int c = 0;
  for (int i = s.size() - 1; i > -1; i--) {
    char a = s[i];
    if (a == x) {
      c++;
    } else {
      break;
    }
  }
  return c;
}
int len_in(string s, char x) {
  int mx = 0;
  int c = 0;
  for (char a : s) {
    if (a == x) {
      c++;
    } else {
      c = 0;
    }
    mx = max(mx, c);
  }
  return mx;
}
int main() {
  int n;
  int MOD = 1e+9 + 7;
  cin >> n;
  vector<string> strings(n);
  for (int i = 0; i < n; i++) {
    cin >> strings[i];
  }
  vector<int> stat(26, 0);
  vector<int> exists(26, 0);
  for (int i = 0; i < 26; i++) {
    char x = 'a' + i;
    int c = 0;
    for (char a : strings[0]) {
      if (a == x) {
        c++;
      } else {
        c = 0;
      }
      stat[i] = max(stat[i], c);
    }
    exists[i] = stat[i] != 0;
  }
  for (int i = 1; i < n; i++) {
    string str = strings[i];
    for (int s = 0; s < 26; s++) {
      char x = 'a' + s;
      if (all_str(str, x)) {
        stat[s] += (stat[s] + 1) * str.size();
        stat[s] %= MOD;
        exists[s] = true;
        continue;
      }
      int len_p = len_pref(str, x);
      int len_s = len_suff(str, x);
      int len_i = len_in(str, x);
      if (exists[s]) {
        stat[s] = max(len_p + len_s + 1, len_i);
        stat[s] %= MOD;
        continue;
      }
      stat[s] = len_i;
      exists[s] |= stat[s] != 0;
      if (stat[s] == 0) {
        if (exists[s]) {
          stat[s] = 1;
        }
      }
      stat[s] %= MOD;
    }
  }
  int mx = -1;
  for (int x : stat) {
    mx = max(mx, x);
  }
  cout << mx << endl;
}
