#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 letter = 'a'; letter <= 'z'; letter++) {
    int ind = letter - 'a';
    long long prev = 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] == letter) prev = max(prev, tmp);
        tmp = 0;
      }
      tmp++;
    }
    if (s[0][s[0].size() - 1] == letter) prev = max(prev, tmp);
    for (int i = 1; i < n; i++) {
      string t = s[i];
      long long left = 0, right = 0, t_beaty = 0;
      tmp = 1;
      bool flag = 0;
      for (int j = 1; j < t.size(); j++) {
        if (t[j] != t[j - 1]) {
          if (flag == 0) {
            flag = 1;
            left = tmp;
          }
          if (t[j - 1] == letter) t_beaty = max(t_beaty, tmp);
          tmp = 0;
        }
        tmp++;
      }
      if (t[t.size() - 1] == letter) t_beaty = max(t_beaty, tmp);
      if (flag == 0) left = tmp;
      right = tmp;
      ans[ind] = t_beaty;
      if (prev > 0) ans[ind] = max(1ll, t_beaty);
      if (right == t.size() && t[0] == letter && prev > 0)
        ans[ind] = max(ans[ind], prev + right * (prev + 1));
      else if (t[0] == letter && t[t.size() - 1] == letter && prev > 0)
        ans[ind] = max(ans[ind], left + right + 1);
      else {
        if (t[0] == letter && prev > 0) ans[ind] = max(ans[ind], left + 1);
        if (t[t.size() - 1] == letter && prev > 0)
          ans[ind] = max(ans[ind], right + 1);
      }
      prev = ans[ind];
    }
  }
  long long res = 0;
  for (auto i : ans) res = max(res, i);
  cout << res;
  return 0;
}
