#include <bits/stdc++.h>
using namespace std;
using ll = long long;
string s[100005];
ll dp[26][100005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= n; i++) {
    int len = s[i].size();
    bool allsame = true;
    for (char ch : s[i]) {
      if (ch != s[i][0]) {
        allsame = false;
        break;
      }
    }
    for (int c = 0; c < 26; c++)
      if (dp[c][i - 1]) dp[c][i] = 1;
    if (allsame) {
      char ch = s[i][0];
      dp[ch - 'a'][i] = max(dp[ch - 'a'][i], len * (dp[ch - 'a'][i - 1] + 1) +
                                                 dp[ch - 'a'][i - 1]);
    } else if (s[i][0] == s[i][len - 1]) {
      int l = 0, r = len - 1;
      while (s[i][l] == s[i][0]) l++;
      while (s[i][r] == s[i][0]) r--;
      if (dp[s[i][0] - 'a'][i - 1])
        dp[s[i][0] - 'a'][i] = max(dp[s[i][0] - 'a'][i], (ll)l + len - r);
      for (int j = l; j <= r;) {
        int k = j;
        while (k <= r and s[i][j] == s[i][k]) k++;
        dp[s[i][j] - 'a'][i] = max(dp[s[i][j] - 'a'][i], (ll)k - j);
        j = k;
      }
    } else {
      for (int l = 0; l < s[i].size();) {
        int j = l;
        while (j < s[i].size() and s[i][j] == s[i][l]) j++;
        if (l == 0) {
          if (dp[s[i][l] - 'a'][i - 1])
            dp[s[i][l] - 'a'][i] = max(dp[s[i][l] - 'a'][i], (ll)j - l + 1);
        } else if (j == s[i].size()) {
          if (dp[s[i][l] - 'a'][i - 1])
            dp[s[i][l] - 'a'][i] = max(dp[s[i][l] - 'a'][i], (ll)j - l + 1);
        }
        dp[s[i][l] - 'a'][i] = max(dp[s[i][l] - 'a'][i], (ll)j - l);
        l = j;
      }
    }
  }
  ll mx = 0;
  for (int i = 0; i < 26; i++) mx = max(mx, dp[i][n]);
  cout << mx << endl;
}
