#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, len[N];
char str[N];
vector<char> s[N];
inline void read(int &i) {
  i = 0;
  char c = getchar();
  bool j = 0;
  for (; !isdigit(c); c = getchar())
    if (c == '-') j = 1;
  for (; isdigit(c); c = getchar()) i = (i << 1) + (i << 3) + c - '0';
  i = j ? -i : i;
}
struct dat {
  int a, l, r, L, R;
  bool t;
} t, ans;
inline dat operator+(dat a, dat b) {
  if (!a.a) return b;
  if (!b.a) return a;
  dat c;
  bool f = (a.r == b.l);
  c.a = max(max(a.a, b.a), f ? a.R + b.L : 0);
  c.l = a.l;
  c.r = b.r;
  c.L = a.L + (a.t && f ? b.L : 0);
  c.R = b.R + (b.t && f ? a.R : 0);
  c.t = a.t & b.t & f;
  return c;
}
inline dat gen(char x) {
  dat a;
  a.a = a.L = a.R = a.t = 1;
  a.l = a.r = x - 'a';
  return a;
}
int main() {
  read(n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", str + 1);
    len[i] = strlen(str + 1);
    s[i].resize(len[i] + 5);
    for (int j = 1; j <= len[i]; ++j) s[i][j] = str[j];
  }
  for (int i = n; i >= 1; --i) {
    ans = t;
    for (int j = 1; j <= len[i]; ++j) ans = ans + gen(s[i][j]), ans = ans + t;
    t = ans;
  }
  printf("%d\n", ans.a);
  return 0;
}
