#include <bits/stdc++.h>
using namespace std;
int wlen[26], pwlen[26], used[26];
char ts[100010];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%s", ts);
    int l = strlen(ts);
    for (int j = 0; j < l; j++) ts[j] -= 'a';
    int s1 = -1, s1c;
    memset(wlen, 0, sizeof wlen);
    for (int j = 0; j < l; j++) {
      if (ts[j] != s1) {
        s1 = ts[j];
        s1c = 1;
      } else
        s1c++;
      wlen[s1] = max(wlen[s1], s1c);
    }
    int il = 0, ir = l - 1;
    for (; il < l && ts[il] == ts[0]; il++)
      ;
    for (; ir >= 0 && ts[ir] == ts[l - 1]; ir--)
      ;
    if (ir == -1) {
      long long t = (long long)l * pwlen[ts[0]] + l + pwlen[ts[0]];
      wlen[ts[0]] = min(t, 1000000010ll);
    } else if (ts[0] == ts[l - 1]) {
      if (used[ts[0]]) wlen[ts[0]] = max(wlen[ts[0]], il + l - ir);
    } else {
      if (used[ts[0]]) wlen[ts[0]] = max(wlen[ts[0]], il + 1);
      if (used[ts[l - 1]]) wlen[ts[l - 1]] = max(wlen[ts[l - 1]], l - ir);
    }
    for (int j = 0; j < 26; j++) wlen[j] = max(wlen[j], used[j]);
    for (int j = 0; j < l; j++) used[ts[j]] = 1;
    memcpy(pwlen, wlen, sizeof wlen);
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, wlen[i]);
  cout << ans;
  return 0;
}
