#include <bits/stdc++.h>
const int MAXN = 3e5 + 10;
const double eps = 1e-8;
using namespace std;
struct edge {
  int t, v;
  edge *next;
} e[MAXN << 1], *h[MAXN], *o = e;
void add(int x, int y, int vul) {
  o->t = y;
  o->v = vul;
  o->next = h[x];
  h[x] = o++;
}
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
long long num[26], num1[26];
char str[MAXN];
int main() {
  int n = read();
  scanf("%s", str + 1);
  int len = strlen(str + 1);
  long long cnt = 1;
  for (int i = 2; i <= len; i++) {
    if (str[i] != str[i - 1])
      num[str[i - 1] - 'a'] = max(num[str[i - 1] - 'a'], cnt), cnt = 1;
    else
      cnt++;
  }
  num[str[len] - 'a'] = max(num[str[len] - 'a'], cnt);
  n--;
  while (n--) {
    scanf("%s", str + 1);
    len = strlen(str + 1);
    for (int i = 0; i <= 25; i++) num1[i] = 0;
    int l = 1, r = 1;
    for (int i = 2; i <= len; i++)
      if (str[i] == str[i - 1])
        l++;
      else
        break;
    for (int i = len - 1; i >= 1; i--)
      if (str[i] == str[i + 1])
        r++;
      else
        break;
    if (l == r && l == len) {
      int t = str[1] - 'a';
      if (num[t])
        num[t] = 1ll * (num[t] + 1) * l + num[t];
      else
        num[t] = l;
      for (int i = 0; i <= 25; i++) {
        if (i == t) continue;
        if (num[i]) num[i] = 1;
      }
    } else {
      cnt = 1;
      for (int i = 2; i <= len; i++) {
        if (str[i] != str[i - 1])
          num1[str[i - 1] - 'a'] = max(num1[str[i - 1] - 'a'], cnt), cnt = 1;
        else
          cnt++;
      }
      num1[str[len] - 'a'] = max(num1[str[len] - 'a'], cnt);
      int t1 = str[1] - 'a';
      int t2 = str[len] - 'a';
      for (int i = 0; i <= 25; i++) {
        if (!num[i]) continue;
        num[i] = 1;
        if (i == t1) num[i] += l;
        if (i == t2) num[i] += r;
      }
      for (int i = 0; i <= 25; i++) num[i] = max(num[i], num1[i]);
    }
  }
  long long maxx = 0;
  for (int i = 0; i <= 25; i++) maxx = max(maxx, num[i]);
  printf("%lld\n", maxx);
}
