#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 7;
int dp[30];
char s[N];
bool vis[N];
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    scanf("%s", s);
    int len = strlen(s);
    vis[s[0] - 'a'] = true;
    bool flag = true;
    for (int i = 1; i < len; i++) {
      vis[s[i] - 'a'] = true;
      if (s[i] != s[i - 1]) flag = false;
    }
    if (flag) {
      int i = s[0] - 'a';
      dp[i] = (dp[i] + 1) * len + dp[i];
      for (int j = 0; j < 26; j++) {
        if (j == i) continue;
        if (vis[j]) dp[j] = 1;
      }
    } else {
      for (int i = 0; i < 26; i++) {
        int cnt1 = 0, cnt2 = 0;
        for (int j = 0; j < len; j++) {
          if (s[j] == 'a' + i)
            cnt1++;
          else
            break;
        }
        for (int j = len - 1; j > 0; j--) {
          if (s[j] == 'a' + i)
            cnt2++;
          else
            break;
        }
        if (dp[i] == 0)
          dp[i] = max(cnt1, cnt2);
        else {
          dp[i] = cnt1 + cnt2 + 1;
        }
        int tmp = 0;
        for (int j = 0; j < len; j++) {
          if (s[j] == 'a' + i)
            tmp++;
          else
            dp[i] = max(dp[i], tmp), tmp = 0;
        }
        dp[i] = max(dp[i], tmp);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) {
    ans = max(ans, dp[i]);
  }
  printf("%d\n", ans);
  return 0;
}
