#include <bits/stdc++.h>
using namespace std;
string p[100010];
long long n, ans, maxn;
int main() {
  cin >> n;
  for (register int i = 1; i <= n; i++) cin >> p[i];
  for (register int c = 0; c <= 25; c++) {
    maxn = 0;
    int judge, l, r, mid;
    for (register int i = 1; i <= n; i++) {
      judge = 1;
      mid = 0;
      for (register int j = 0; j <= (int)p[i].size() - 1; j++)
        if (p[i][j] != c + 'a') judge = 0;
      int cnt = 0, bo = 1;
      for (register int j = 0; j <= (int)p[i].size() - 1; j++)
        cnt += bo, bo = (bo && p[i][j] == c + 'a');
      l = cnt - 1;
      cnt = 0;
      bo = 1;
      for (register int j = p[i].size() - 1; j >= 0; j--)
        cnt += bo, bo = (bo && p[i][j] == c + 'a');
      r = cnt - 1;
      cnt = 0;
      bo = 1;
      for (register int j = 0; j <= (int)p[i].size() - 1; j++) {
        cnt = (p[i][j] == c + 'a') ? cnt + 1 : 0;
        mid = max(mid, cnt);
      }
      if (judge)
        maxn = maxn + (maxn + 1) * p[i].size();
      else if (maxn == 0)
        maxn = mid;
      else
        maxn = max(mid, l + r + 1);
    }
    ans = max(ans, maxn);
  }
  cout << ans;
}
