#include <bits/stdc++.h>
using namespace std;
string s[100005];
int n, len1, len2, ans, flag;
char L, R, c;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> s[i];
  int len = s[n].size();
  L = s[n][0], R = s[n][len - 1];
  for (int i = 0; i < len; i++)
    if (s[n][i] == L)
      len1++;
    else
      break;
  for (int i = len - 1; i >= 0; i--)
    if (s[n][i] == R)
      len2++;
    else
      break;
  ans = 1;
  int cnt = 1;
  for (int i = 0; i < len; i++)
    if (s[n][i] == s[n][i + 1])
      ans = max(ans, ++cnt);
    else
      cnt = 1;
  if (L == R && ans == len) flag = 1;
  for (int i = n - 1; i >= 1; i--) {
    len = s[i].size();
    int tmpl = 0, tmpr = 0, cntl = 0, cntr = 0;
    for (int j = 0; j < len; j++)
      if (s[i][j] == L)
        cntl = max(cntl, ++tmpl);
      else
        tmpl = 0;
    for (int j = 0; j < len; j++)
      if (s[i][j] == R)
        cntr = max(cntr, ++tmpr);
      else
        tmpr = 0;
    if (flag) {
      ans = max(ans, cntl * (len1 + 1) + len1);
    } else {
      if (cntl) ans = max(ans, 1 + len1);
      if (cntr) ans = max(ans, 1 + len2);
      if (L == R && cntl && cntr) ans = max(ans, 1 + len1 + len2);
    }
    if (flag) {
      tmpl = len1, tmpr = len2;
      for (int j = 0; j < len; j++)
        if (s[i][j] == L)
          len1 += (1 + tmpl);
        else {
          flag = 0;
          break;
        }
      for (int j = len - 1; j >= 0; j--)
        if (s[i][j] == R)
          len2 += (1 + tmpr);
        else {
          flag = 0;
          break;
        }
    }
    ans = max(ans, max(len1, len2));
  }
  cout << ans << endl;
}
