#include <bits/stdc++.h>
using namespace std;
const long long inff = 0x3f3f3f3f3f3f3f3f;
int a[28], b[28];
int now[28];
char s[100008];
int g[100008];
int main() {
  int n;
  int h, t, k;
  scanf("%d", &n);
  while (n--) {
    for (int i = 0; i < 26; i++) {
      now[i] = 0;
    }
    scanf("%s", &s);
    k = strlen(s) - 1;
    h = s[0] - 'a';
    int tot = 0;
    g[tot] = 1;
    for (int i = 1; s[i]; i++) {
      if (s[i] == s[i - 1]) {
        g[tot]++;
      } else {
        now[s[i - 1] - 'a'] = max(now[s[i - 1] - 'a'], g[tot]);
        tot++;
        g[tot] = 1;
      }
    }
    now[s[k] - 'a'] = max(now[s[k] - 'a'], g[tot]);
    for (int i = 0; i < 26; i++) {
      if (a[i] == 0 && now[i] == 0) {
        b[i] = 0;
      } else if (a[i] <= now[i]) {
        b[i] = now[i];
      } else if (a[i] > now[i]) {
        b[i] = max(now[i], 1);
      }
    }
    if (tot == 0) {
      b[s[0] - 'a'] = (a[s[0] - 'a'] + 1) * (now[s[0] - 'a']) + a[s[0] - 'a'];
    } else if ((s[0] - 'a') == (s[k] - 'a')) {
      if (a[s[0] - 'a'] > 0) {
        b[s[0] - 'a'] = max(b[s[0] - 'a'], g[0] + g[tot] + 1);
      }
    } else {
      if (a[s[0] - 'a'] > 0) {
        b[s[0] - 'a'] = max(b[s[0] - 'a'], g[0] + 1);
      }
      if (a[s[k] - 'a'] > 0) {
        b[s[k] - 'a'] = max(b[s[k] - 'a'], g[tot] + 1);
      }
    }
    for (int i = 0; i < 26; i++) {
      a[i] = b[i];
    }
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) {
    ans = max(ans, a[i]);
  }
  cout << ans << endl;
}
