#include <bits/stdc++.h>
using namespace std;
int Read() {
  int p = 0, f = 0;
  char c = getchar();
  for (; c < '0' || c > '9'; c = getchar()) f |= (c == '-');
  for (; c >= '0' && c <= '9'; c = getchar()) p = p * 10 + c - '0';
  if (f) p = -p;
  return p;
}
string s[100005];
bool a[100005][26], b[100005];
long long dfs(int x, char c) {
  if (x == 0) return 0;
  int ans = a[x - 1][c - 'a'], sz = s[x].size();
  if (b[x] && s[x][0] == c) {
    ans = dfs(x - 1, c);
    return (ans + 1) * sz + ans;
  } else {
    int q = 0, h = 0, last = -1;
    for (int i = 0; i < sz; ++i) {
      if (s[x][i] == c && last == -1) last = i;
      if (s[x][i] == c)
        ans = max(ans, i - last + 1);
      else
        last = -1;
    }
    for (int i = 0; i < sz; ++i) {
      if (s[x][i] == c)
        q++;
      else
        break;
    }
    for (int i = sz - 1; ~i; --i) {
      if (s[x][i] == c)
        h++;
      else
        break;
    }
    if (s[x][0] == c && s[x - 1][sz - 1] == s[x][0] && a[x - 1][c - 'a'])
      ans = max(ans, q + h + 1);
    if (s[x][0] == c && a[x - 1][c - 'a']) ans = max(ans, q + 1);
    if (s[x][sz - 1] == c && a[x - 1][c - 'a']) ans = max(ans, h + 1);
    if (s[x][0] == c) ans = max(ans, q);
    if (s[x][sz - 1] == c) ans = max(ans, h);
    return ans;
  }
}
int main() {
  int n = Read();
  for (int i = 1; i <= n; i++) cin >> s[i], b[i] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < (int)s[i].size(); j++)
      if (s[i][j] != s[i][j - 1]) {
        b[i] = 0;
        break;
      }
    for (int j = 0; j < (int)s[i].size(); j++) a[i][s[i][j] - 'a'] = 1;
    for (int j = 0; j < 25; ++j) a[i][j] |= a[i - 1][j];
  }
  int ans = 1, q = 1, h = 1, last = 0, sz = s[n].size();
  for (int i = 1; i < sz; i++) {
    if (last == 0 && s[n][i] == s[n][0]) q++;
    if (s[n][i] == s[n][last])
      ans = max(ans, i - last + 1);
    else
      last = i;
  }
  for (int i = sz - 2; i >= 0; i--)
    if (s[n][i] == s[n][sz - 1])
      h++;
    else
      break;
  if (!b[n]) {
    if (s[n][0] == s[n][sz - 1] && a[n - 1][s[n][0] - 'a'])
      ans = max(ans, q + h + 1);
    if (a[n - 1][s[n][0] - 'a']) ans = max(ans, q + 1);
    if (a[n - 1][s[n][sz - 1] - 'a']) ans = max(ans, h + 1);
    ans = max(ans, max(q, h));
    cout << ans;
    return 0;
  }
  int t = dfs(n - 1, s[n][0]);
  cout << (t + 1) * sz + t;
}
