#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int n;
char s[MAXN];
int max_c_len[30];
int main() {
  cin >> n;
  memset(max_c_len, 0, sizeof(max_c_len));
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    int len = strlen(s);
    bool flag = true;
    for (int j = 1; j < len; j++) {
      if (s[j] != s[j - 1]) {
        flag = false;
      }
    }
    int flag_num;
    if (flag) {
      flag_num = s[0] - 'a' + 1;
    }
    int xx[30];
    memset(xx, 0, sizeof(xx));
    int j;
    if (!flag) {
      for (j = 0; j < len; j++) {
        int tmp = s[j] - 'a' + 1;
        xx[tmp] = max(1, xx[tmp]);
        if (j == len - 1) {
          break;
        }
        if (s[j] == s[j + 1]) {
          int bnt = 1;
          int K;
          for (K = j + 1; K < len; K++) {
            if (s[K] == s[j]) {
              bnt++;
            } else
              break;
          }
          int tmp = s[j] - 'a' + 1;
          xx[tmp] = max(bnt, xx[tmp]);
          K--;
          j = K;
        }
      }
    }
    int pre = s[0] - 'a' + 1, rear = s[len - 1] - 'a' + 1;
    int cnt1 = 0;
    int cnt2 = 0;
    for (int j = 0; j < len; j++) {
      if (s[j] - 'a' + 1 == pre) {
        cnt1++;
      } else
        break;
    }
    for (int j = len - 1; j >= 0; j--) {
      if (s[j] - 'a' + 1 == rear) {
        cnt2++;
      } else
        break;
    }
    for (int k = 1; k <= 26; k++) {
      if (max_c_len[k] == 0) {
        if ((flag) && (flag_num == k)) {
          max_c_len[k] = len;
        } else {
          max_c_len[k] = xx[k];
        }
      } else {
        if ((flag) && (flag_num == k)) {
          max_c_len[k] = max_c_len[k] + (max_c_len[k] + 1) * len;
        } else {
          int temp = 1;
          if (pre == k) {
            temp += cnt1;
          }
          if (rear == k) {
            temp += cnt2;
          }
          max_c_len[k] = temp;
          max_c_len[k] = max(xx[k], max_c_len[k]);
        }
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= 26; i++) {
    ans = max(ans, max_c_len[i]);
  }
  cout << ans << endl;
  return 0;
}
