#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int pref(const string& s, int c) {
  int i = 0;
  while (i < s.size() and s[i] == c) i++;
  return i;
}
int suf(const string& s, int c) {
  int i = (int)s.size() - 1;
  while (i >= 0 and s[i] == c) i--;
  return (int)s.size() - 1 - i;
}
int beauty(const string& s, int c) {
  int i = 0, ret = 0, b = 0;
  while (i < s.size()) {
    if (s[i] == c)
      b++;
    else
      b = 0;
    ret = max(ret, b);
    i++;
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<string> p;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    p.push_back(s);
  }
  int ans = 0;
  for (int l = 'a'; l <= 'z'; l++) {
    int b = beauty(p[0], l);
    for (int i = 1; i < n; i++) {
      int sum = pref(p[i], l) + suf(p[i], l);
      if (sum == 2 * p[i].size())
        b += (b + 1) * (int)p[i].size();
      else {
        if (b > 0)
          b = max(beauty(p[i], l), sum + 1);
        else
          b = beauty(p[i], l);
      }
    }
    ans = max(ans, b);
  }
  cout << ans << '\n';
  return 0;
}
