9
lfpgbnlzyn
c
s
w
r
m
q
y
yinfblfcdhidphyfvgkxyuwomahiibbhnigdslsguhjkplibnhhrshtekwgefxeugyyyyy
 6
u
p
m
z
v
vv
 4
qe
nd
iqryhukieskfvaeettersinksrmazelxtgvartuz
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
 6
nf
ysvchtjkfgsbyfzxjaykey
advqnf
wl
pi
ppppfvvmaebvhkoagppppp
 3
j
k
kkailgwqnxtdsttkkkkkkk
 4
o
yhnx
e
ennn
 10
j
dyfu
udzj
wwow
xtnw
f
c
q
o
gggg
 6
w
g
c
j
y
f
 4
r
o
w
wwwwwwwwww
 2
zxwp
ppppctfisvflhtjggg
 5
m
g
u
t
tttt
 2
n
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
 3
lt
en
eeeeeeeeee
 4
vr
hp
l
llbn

7 5 541 10 10 4 4 1 21 5 9 93 21 3
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
void wl(int x) { printf("%d\n", x); }
void wl(double x) { printf("%lf\n", x); }
void wl(string x) { printf("%s\n", x.c_str()); }
void wl(long long x) { printf("%lld\n", x); }
void w(int x) { printf("%d ", x); }
void w(double x) { printf("%lf ", x); }
void w(string x) { printf("%s ", x.c_str()); }
void w(long long x) { printf("%lld ", x); }
vector<string> v;
struct attrib {
  char l, r;
  int long long = 0, rr = 0;
  int mx = 0;
  bool full = 0;
  void copy(attrib a) {
    l = a.l;
    r = a.r;
    long long = a.long long;
    rr = a.rr;
    full = a.full;
    mx = a.mx;
  }
  void print() { printf("%d\n", max(mx, max(long long, rr))); }
  void bug() {
    cout << "l"
         << " = " << l;
    printf("\n");
    ;
    cout << "r"
         << " = " << r;
    printf("\n");
    ;
    cout << "ll"
         << " = " << long long;
    printf("\n");
    ;
    cout << "rr"
         << " = " << rr;
    printf("\n");
    ;
    cout << "mx"
         << " = " << mx;
    printf("\n");
    ;
    printf("full = %d\n", (full) ? 1 : 0);
  }
};
int main() {
  int n;
  scanf("%d", &n);
  ;
  attrib ans, New;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    ;
    v.push_back(s);
  }
  for (int i = n - 1; i >= 0; i--) {
    if (i == n - 1) {
      ans.l = v[i][0];
      ans.r = v[i][v[i].size() - 1];
      for (int j = 0; j < v[i].size(); j++) {
        if (v[i][j] == ans.l)
          ans.long long ++;
        else
          break;
      }
      for (int j = v[i].size() - 1; j >= 0; j--) {
        if (v[i][j] == ans.r)
          ans.rr++;
        else
          break;
      }
      char tmp = 'A';
      int now = 0;
      for (int j = 0; j < v[i].size(); j++) {
        if (v[i][j] == tmp)
          now++;
        else
          now = 1;
        tmp = v[i][j];
        ans.mx = max(ans.mx, now);
      }
      if (ans.mx == v[i].size()) ans.full = 1;
    } else {
      if (ans.full) {
        char want = ans.l;
        New.l = ans.l;
        New.long long = ans.long long;
        New.r = ans.r;
        New.rr = ans.rr;
        for (int j = 0; j < v[i].size(); j++) {
          if (v[i][j] == want)
            New.long long += (1 + ans.long long);
          else
            break;
        }
        for (int j = v[i].size() - 1; j >= 0; j--) {
          if (v[i][j] == want)
            New.rr += (1 + ans.rr);
          else
            break;
        }
        int now = 1;
        for (int j = 0; j < v[i].size(); j++) {
          if (v[i][j] == want) {
            if (j == v[i].size() - 1) {
              now += (1 + ans.long long);
              New.full = 1;
            } else
              now += (1 + (2 * ans.long long));
          } else
            break;
        }
        New.mx = max(now, max(New.long long, New.rr));
      } else {
        New.l = ans.l;
        New.long long = ans.long long;
        New.r = ans.r;
        New.rr = ans.rr;
        New.full = 0;
        int now = 1;
        for (int j = 0; j < v[i].size(); j++) {
          if (v[i][j] == ans.l && v[i][j] == ans.r)
            now = max(now, 1 + ans.long long + ans.rr);
          else if (v[i][j] == ans.l)
            now = max(now, 1 + ans.long long);
          else if (v[i][j] == ans.r)
            now = max(now, 1 + ans.rr);
          else
            now = max(now, 1);
        }
        New.mx = max(max(ans.mx, now), max(New.long long, New.rr));
      }
      ans.copy(New);
    }
  }
  ans.print();
}
