#include <bits/stdc++.h>
using namespace std;
long long res[26][200000];
int main() {
  int n;
  cin >> n;
  memset(res, 0, sizeof(res));
  string s;
  long long vec[26];
  for (int i = 1; i <= n; i++) {
    memset(vec, 0, sizeof(vec));
    cin >> s;
    bool bo = true;
    int ta = s.size();
    for (int j = 0; j < s.size() - 1; j++)
      if (s[j] != s[j + 1]) {
        bo = false;
        break;
      }
    if (bo) {
      for (int j = 0; j < 26; j++) res[j][i] = res[j][i - 1] > 0;
      int ax = s[0] - 'a';
      res[ax][i] = (res[ax][i - 1] + 1ll) * ((long long)ta) + res[ax][i - 1];
      if (res[ax][i] > 1e9) res[ax][i] = 1;
    } else {
      if (s[0] == s[s.size() - 1]) {
        int b, e, can = 0;
        for (int j = 0; j < ta - 1; j++) {
          can++;
          if (s[j] != s[j + 1]) {
            b = j + 1;
            break;
          }
        }
        for (int j = ta - 1; j > 0; j--) {
          can++;
          if (s[j] != s[j - 1]) {
            e = j - 1;
            break;
          }
        }
        char ch;
        bool be = false;
        long long cani;
        for (int j = b; j <= e; j++) {
          if (be) {
            if (s[j] == ch)
              cani++;
            else {
              int ax = ch - 'a';
              vec[ax] = max(vec[ax], cani);
              cani = 1;
              ch = s[j];
            }
          } else {
            ch = s[j];
            cani = 1;
            be = true;
          }
        }
        int ax = ch - 'a';
        vec[ax] = max(vec[ax], cani);
        cani = 1;
        ax = s[0] - 'a';
        if (can >= vec[ax]) vec[ax] = can + (res[ax][i - 1] > 0);
        for (int j = 0; j < 26; j++)
          res[j][i] = max((long long)(res[j][i - 1] > 0), vec[j]);
      } else {
        char ch;
        bool be = false;
        long long cani;
        for (int j = 0; j < ta; j++) {
          if (be) {
            if (s[j] == ch)
              cani++;
            else {
              int ax = ch - 'a';
              vec[ax] = max(vec[ax], cani);
              cani = 1;
              ch = s[j];
            }
          } else {
            ch = s[j];
            cani = 1;
            be = true;
          }
        }
        int ax = ch - 'a';
        vec[ax] = max(vec[ax], cani);
        cani = 0;
        for (int j = 0; j < ta - 1; j++) {
          cani++;
          if (s[j] != s[j + 1]) break;
        }
        ax = s[0] - 'a';
        if (cani >= vec[ax]) vec[ax] = cani + (res[ax][i - 1] > 0);
        cani = 0;
        for (int j = ta - 1; j > 0; j--) {
          cani++;
          if (s[j] != s[j - 1]) break;
        }
        ax = s[ta - 1] - 'a';
        if (cani >= vec[ax]) vec[ax] = cani + (res[ax][i - 1] > 0);
        for (int j = 0; j < 26; j++)
          res[j][i] = max((long long)(res[j][i - 1] > 0), vec[j]);
      }
    }
  }
  long long resi = 0;
  for (int i = 0; i < 26; i++) resi = max(resi, res[i][n]);
  cout << resi << endl;
  return 0;
}
