#include <bits/stdc++.h>
using namespace std;
long long int mul(long long int x, long long int y) {
  long long int ans = 1;
  while (y > 0) {
    if (y & 1) ans = (ans * x) % 1000000007;
    y /= 2;
    x = (x * x) % 1000000007;
  }
  return ans;
};
vector<long long int> fun(string str) {
  long long int i, size = str.size(), cnt = 0;
  vector<long long int> h(26, 0);
  h[str[0] - 'a'] = 1;
  cnt = 1;
  for (i = 1; i < size; i++) {
    if (str[i] == str[i - 1])
      ++cnt;
    else
      cnt = 1;
    h[str[i] - 'a'] = max(cnt, h[str[i] - 'a']);
  }
  return h;
}
long long int start_cnt(string str) {
  long long int i, size = str.size(), cnt = 1;
  for (i = 1; i < size; i++)
    if (str[i] == str[0])
      ++cnt;
    else
      break;
  return cnt;
}
long long int end_cnt(string str) {
  long long int i, size = str.size(), cnt = 1;
  for (i = size - 2; i >= 0; i--)
    if (str[i] == str[size - 1])
      ++cnt;
    else
      break;
  return cnt;
}
void pp(vector<long long int> v) {
  long long int i, size = v.size();
  for (i = 0; i < size; i++) cout << v[i] << " ";
  cout << "\n";
  return;
}
int main() {
  long long int n, i, size, aa, bb, j;
  string str;
  scanf("%lld", &n);
  vector<long long int> ans, last;
  for (i = 1; i <= n; i++) {
    cin >> str;
    size = str.size();
    ans = fun(str);
    aa = start_cnt(str);
    bb = end_cnt(str);
    if (i > 1) {
      for (j = 0; j < 26; j++)
        if (last[j] > 0 && ans[j] == 0) ans[j] = 1;
      if (size == aa)
        ans[str[0] - 'a'] =
            (last[str[0] - 'a'] + 1) * size + last[str[0] - 'a'];
      else if (str[0] == str[size - 1] && last[str[0] - 'a'] > 0)
        ans[str[0] - 'a'] = max(ans[str[0] - 'a'], bb + 1 + aa);
      else {
        if (last[str[0] - 'a'] > 0)
          ans[str[0] - 'a'] = max(ans[str[0] - 'a'], 1 + aa);
        if (last[str[size - 1] - 'a'] > 0)
          ans[str[size - 1] - 'a'] = max(ans[str[size - 1] - 'a'], bb + 1);
      }
    }
    last = ans;
  }
  long long int fin = 0;
  for (i = 0; i < 26; i++) fin = max(fin, last[i]);
  cout << fin << "\n";
  return 0;
}
