#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using ll = long long;
const int mxN = 100001;
vector<pair<int, int>> arr[mxN];
int curr[26];
int pre[26];
int n;
string alph = "abcdefghijklmnopqrstuvwxyz";
map<char, int> mp;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < 26; ++i) {
    mp[alph[i]] = i;
  }
  string k;
  for (int i = 0; i < n; ++i) {
    cin >> k;
    arr[i].push_back({mp[k[0]], 1});
    for (int j = 1; j < k.size(); ++j) {
      if (k[j] == k[j - 1]) {
        arr[i].back().second++;
      } else {
        arr[i].push_back({mp[k[j]], 1});
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 26; ++j) {
      curr[j] = (pre[j] > 0);
    }
    if (arr[i].size() == 1) {
      int k = arr[i][0].first;
      for (int j = 0; j < 26; ++j) {
        if (j == k)
          curr[j] = pre[j] + arr[i][0].second * (pre[j] + 1);
        else
          curr[j] = (pre[j] > 0);
      }
    } else {
      for (auto p : arr[i]) {
        curr[p.first] = max(curr[p.first], p.second);
      }
      if (arr[i][0].first == arr[i].back().first) {
        int col = arr[i][0].first;
        if (pre[col] > 0) {
          curr[col] =
              max(curr[col], arr[i][0].second + arr[i].back().second + 1);
        }
      } else {
        int col = arr[i][0].first;
        if (pre[col] > 0) {
          curr[col] = max(curr[col], arr[i][0].second + 1);
        }
        col = arr[i].back().first;
        if (pre[col] > 0) {
          curr[col] = max(curr[col], arr[i].back().second + 1);
        }
      }
    }
    for (int j = 0; j < 26; ++j) {
      pre[j] = curr[j];
    }
  }
  int ans = 0;
  for (int i = 0; i < 26; ++i) {
    ans = max(ans, curr[i]);
  }
  cout << ans << "\n";
  return 0;
}
