#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return x * f;
}
const int N = 100010, AS = 26;
int tans;
struct Data {
  int lc, lnum, rc, rnum, len;
  Data() { lc = lnum = rc = rnum = len = 0; }
};
inline Data operator+(const Data& t1, const char& t2) {
  Data ans = t1;
  char c = t2 - 'a';
  if (c == ans.rc) {
    ++ans.rnum;
  } else {
    ans.rc = c, ans.rnum = 1;
  }
  if (ans.lnum == ans.len && ans.lc == c) ++ans.lnum;
  if (!ans.len) ans.lc = c, ans.lnum = 1;
  ++ans.len;
  tans = max(tans, ans.rnum);
  return ans;
}
inline Data operator+(const Data& t1, const Data& t2) {
  Data ans;
  ans.lc = t1.lc, ans.rc = t2.rc, ans.len = t1.len + t2.len;
  ans.lnum = t1.lnum, ans.rnum = t2.rnum;
  if (t1.rc == t2.lc) {
    tans = max(tans, t1.rnum + t2.lnum);
    if (t1.lnum == t1.len) ans.lnum += t2.lnum;
    if (t2.rnum == t2.len) ans.rnum += t1.rnum;
  }
  return ans;
}
string s[N];
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> s[i];
  Data now, pre;
  int tl = s[n].size();
  for (int j = 0; j < tl; ++j) now = now + s[n][j];
  pre = now;
  for (int i = n - 1; i; --i) {
    int len = s[i].size();
    for (int j = 0; j < len; ++j) now = now + s[i][j] + pre;
    pre = now;
  }
  cout << tans << endl;
  return 0;
}
