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;
void scan(const string &str, int &lm, int &rm, int &cl) {
  lm = rm = 0;
  for (int i = 0; i < str.size(); i++) {
    if (str[i] == str[0])
      lm++;
    else
      break;
  }
  for (int i = str.size() - 1; i >= 0; i--) {
    if (str[i] == str.back())
      rm++;
    else
      break;
  }
  if (lm == str.size()) cl = 1;
}
int get(const string &str) {
  int ans = 1;
  int now = 1;
  for (int i = 1; i < str.size(); i++) {
    if (str[i] == str[i - 1])
      now++;
    else {
      now = 1;
    }
    ans = max(now, ans);
  }
  return ans;
}
int main() {
  int n;
  cin >> n;
  vector<string> data;
  for (int i = 0; i < n; i++) {
    string t;
    cin >> t;
    data.push_back(t);
  }
  reverse(data.begin(), data.end());
  string raw(data[0]);
  int lm, rm, cl;
  scan(raw, lm, rm, cl);
  int ans = get(raw);
  for (int i = 1; i < n; i++) {
    string str(data[i]);
    bool flag = true;
    int now_left = rm;
    for (auto x : str) {
      if (x != str[0]) flag = false;
      if (x == raw.back()) {
        ans = max(ans, now_left + 1);
      }
      if (x == raw.front()) {
        ans = max(ans, lm + 1);
      }
      if (x == raw.front() && x == raw.back()) {
        ans = max(ans, lm + now_left + 1);
      }
      if (cl && x == raw.front()) {
        now_left += 1 + lm;
      } else {
        now_left = rm;
      }
    }
    if (cl) {
      int tmp = lm;
      for (auto x : str) {
        if (x == raw[0])
          tmp += 1 + lm;
        else
          break;
      }
      lm = tmp;
      tmp = rm;
      for (int x = str.size() - 1; x >= 0; x--) {
        if (str[x] == raw[0])
          tmp += 1 + rm;
        else
          break;
      }
      rm = tmp;
    }
    if (flag && str[0] == raw[0])
      cl = 1;
    else
      cl = 0;
  }
  printf("%d\n", ans);
}
