#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 1;
char s[maxn];
int cnt[128];
int main() {
  int n, len, ans, l, r;
  bool same;
  cin >> n >> s, len = strlen(s);
  for (int i = 0; i < len;) {
    int j = i, k = 0;
    while (j < len && s[j] == s[i]) ++j;
    cnt[s[i]] = max(cnt[s[i]], j - i), i = j;
  }
  while (--n) {
    cin >> s, len = strlen(s), ans = 0, same = true;
    for (int i = 1; i < len && same; ++i) same = s[i] == s[0];
    if (same) {
      for (int i = 'a'; i <= 'z'; ++i)
        if (cnt[i] && i != s[0]) cnt[i] = 1;
      ans = cnt[s[0]] = (cnt[s[0]] + 1) * len + cnt[s[0]];
    } else {
      l = 0, r = 0;
      while (l < len && s[l] == s[0]) ++l;
      while (r < len && s[len - 1 - r] == s[len - 1]) ++r;
      for (int i = 'a'; i <= 'z'; ++i)
        if (cnt[i])
          cnt[i] = 1,
          ans = max(ans, 1 + (i == s[0] ? l : 0) + (i == s[len - 1] ? r : 0));
      if (s[0] == s[len - 1])
        cnt[s[0]] = cnt[s[0]] ? 1 + l + r : max(l, r);
      else
        cnt[s[0]] = (cnt[s[0]] ? 1 : 0) + l,
        cnt[s[len - 1]] = (cnt[s[len - 1]] ? 1 : 0) + r;
      for (int i = 0; i < len;) {
        int j = i, k = 0;
        while (j < len && s[j] == s[i]) ++j;
        cnt[s[i]] = max(cnt[s[i]], j - i), ans = max(ans, j - i), i = j;
      }
    }
  }
  cout << ans;
  return 0;
}
