#include <bits/stdc++.h>
using namespace std;
string s;
long long max_len[26], max_len1[26];
int main() {
  int n;
  bool same;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> s;
    same = true;
    long long tmp = 1;
    int x;
    for (int j = 0; j < 26; ++j) {
      max_len1[j] = 0;
    }
    for (int j = 1; j < s.length(); ++j) {
      if (s[j] == s[j - 1]) {
        ++tmp;
      } else {
        same = false;
        x = s[j - 1] - 'a';
        max_len1[x] = max(max_len1[x], tmp);
        tmp = 1;
      }
    }
    x = s[s.length() - 1] - 'a';
    max_len1[x] = max(max_len1[x], tmp);
    if (same) {
      x = s[0] - 'a';
      max_len[x] = max_len[x] + (max_len[x] + 1) * max_len1[x];
      for (int j = 0; j < 26; ++j) {
        if (j != x) {
          max_len[j] = min(max_len[j], 1ll);
        }
      }
    } else {
      int pre_len = 1, suf_len = 1, pre_x = s[0] - 'a',
          suf_x = s[s.length() - 1] - 'a';
      for (int i = 1; i < s.length(); ++i) {
        if (s[i] == s[0]) {
          ++pre_len;
        } else {
          break;
        }
      }
      for (int i = s.length() - 2; i >= 0; --i) {
        if (s[i] == s[s.length() - 1]) {
          ++suf_len;
        } else {
          break;
        }
      }
      for (int j = 0; j < 26; ++j) {
        if (max_len[j] == 0) {
          max_len[j] = max_len1[j];
          continue;
        }
        if (j != pre_x && j != suf_x) {
          max_len[j] = max(max_len1[j], 1ll);
          continue;
        }
        if (pre_x == suf_x) {
          max_len[pre_x] = max(max_len1[pre_x], pre_len + suf_len + 1ll);
        } else {
          max_len[pre_x] = max(max_len1[pre_x], pre_len + 1ll);
          max_len[suf_x] = max(max_len1[suf_x], suf_len + 1ll);
        }
      }
    }
    for (int j = 0; j < 26; ++j) {
      if (max_len[j] > 1000000000) {
        max_len[j] = 1000000000;
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < 26; ++i) {
    ans = max(ans, max_len[i]);
  }
  cout << ans << endl;
  return 0;
}
