#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  vector<long long> ans(26);
  for (char l = 'a'; l <= 'z'; l++) {
    long long t = 0, tmp = 1;
    for (int j = 1; j < s[0].size(); j++) {
      if (s[0][j] != s[0][j - 1]) {
        if (s[0][j - 1] == l) {
          t = max(t, tmp);
        }
        tmp = 0;
      }
      tmp++;
    }
    if (s[0][s[0].size() - 1] == l) {
      t = max(t, tmp);
    }
    for (int i = 1; i < n; i++) {
      string x = s[i];
      long long left = 0, right = 0, t1 = 0;
      tmp = 1;
      bool fl = 0;
      for (int j = 1; j < x.size(); j++) {
        if (x[j] != x[j - 1]) {
          if (fl == 0) {
            fl = 1;
            left = tmp;
          }
          if (x[j - 1] == l) {
            t1 = max(t1, tmp);
          }
          tmp = 0;
        }
        tmp++;
      }
      if (x[x.size() - 1] == l) {
        t1 = max(t1, tmp);
      }
      if (fl == 0) {
        left = tmp;
      }
      right = tmp;
      ans[l - 'a'] = t1;
      if (t > 0) {
        ans[l - 'a'] = max(1ll, t1);
      }
      if (right == x.size() && x[0] == l && t > 0) {
        ans[l - 'a'] = max(ans[l - 'a'], t + right * (t + 1));
      } else if (x[0] == l && x[x.size() - 1] == l && t > 0) {
        ans[l - 'a'] = max(ans[l - 'a'], left + right + 1);
      }
      if (x[0] == l && t > 0) {
        ans[l - 'a'] = max(ans[l - 'a'], left + 1);
      }
      if (x[x.size() - 1] == l && t > 0) {
        ans[l - 'a'] = max(ans[l - 'a'], right + 1);
      }
      t = ans[l - 'a'];
    }
  }
  long long res = 0;
  for (auto i : ans) {
    res = max(res, i);
  }
  cout << res;
  return 0;
}
