#include <bits/stdc++.h>
using namespace std;
void start(vector<int> &arr, pair<char, int> &prefAns, pair<char, int> &sufAns,
           string &s) {
  int i;
  for (i = 0; i < s.size(); ++i) {
    int cnt = 0;
    while (i + 1 != s.size() && s[i] == s[i + 1]) {
      ++cnt;
      ++i;
    }
    arr[s[i]] = max(arr[s[i]], cnt + 1);
  }
  i = 0;
  while (i + 1 != s.size() && s[i] == s[i + 1]) {
    ++i;
  }
  prefAns = {s[0], i + 1};
  i = s.size() - 1;
  while (i - 1 != -1 && s[i] == s[i - 1]) {
    --i;
  }
  sufAns = {s[s.size() - 1], s.size() - i};
}
char same(string &s) {
  int res = s[0];
  for (auto c : s) {
    if (res != c) {
      return -1;
    }
  }
  return res;
}
void relax(vector<int> &ans, pair<char, int> &prefAns, pair<char, int> &sufAns,
           string &s) {
  for (auto c : s) {
    ans[c] = max(ans[c], (sufAns.first == c) * sufAns.second + 1 +
                             (prefAns.first == c) * prefAns.second);
  }
}
int max(vector<int> &arr) {
  int res = 0;
  for (auto elem : arr) {
    res = max(res, elem);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<string> arr(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  vector<int> ans('z' + 1);
  pair<char, int> prefAns;
  pair<char, int> sufAns;
  start(ans, prefAns, sufAns, arr[n - 1]);
  bool flag = (same(arr[n - 1]) != -1);
  for (int i = n - 2; i >= 0; --i) {
    char c = same(arr[i]);
    if (flag && (c != arr[n - 1][0])) {
      c = arr[n - 1][0];
      vector<int> tmpAns('z' + 1);
      pair<char, int> tmpPrefAns;
      pair<char, int> tmpSufAns;
      start(tmpAns, tmpPrefAns, tmpSufAns, arr[i]);
      ans[c] = ans[c] * (tmpAns[c] + 1) + tmpAns[c];
      if (tmpPrefAns.first == c) {
        prefAns = {
            c, prefAns.second * (tmpPrefAns.second + 1) + tmpPrefAns.second};
      }
      if (tmpSufAns.first == c) {
        sufAns = {c, sufAns.second * (tmpSufAns.second + 1) + tmpSufAns.second};
      }
      flag = false;
      continue;
    }
    if (flag) {
      ans[c] = ans[c] * (arr[i].size() + 1) + arr[i].size();
      prefAns = {c, ans[c]};
      sufAns = {c, ans[c]};
    } else {
      relax(ans, prefAns, sufAns, arr[i]);
    }
  }
  cout << max(ans) << endl;
  return 0;
}
