#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  vector<string> vs;
  long long len, pnum, snum, n;
  char f_c, l_c;
  bool one;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> str;
    vs.push_back(str);
  }
  reverse(vs.begin(), vs.end());
  len = 1, pnum = 1, snum = 1;
  f_c = vs[0][0], l_c = vs[0][vs[0].size() - 1];
  long long temp = 1;
  for (int i = 1; i < vs[0].size(); i++) {
    if (vs[0][i] == vs[0][i - 1]) {
      temp++;
      len = max(len, temp);
    } else {
      temp = 1;
    }
  }
  for (int i = 1; i < vs[0].size(); i++) {
    if (vs[0][i] == vs[0][i - 1]) {
      pnum++;
    } else
      break;
  }
  for (int i = vs[0].size() - 2; i >= 0; i--) {
    if (vs[0][i] == vs[0][i + 1]) {
      snum++;
    } else
      break;
  }
  if (len == vs[0].size())
    one = true;
  else
    one = false;
  for (int i = 1; i < vs.size(); i++) {
    str = vs[i];
    bool one2 = true;
    for (int j = 1; j < str.size(); j++) {
      if (str[j] != str[j - 1]) {
        one2 = false;
        break;
      }
    }
    if (f_c != str[0]) one2 = false;
    temp = 0;
    if (one) {
      temp = 0;
      int j;
      bool ok = true;
      for (j = 0; j < str.size(); j++) {
        if (str[j] == l_c) {
          temp += (len + 1);
          pnum = max(pnum, temp);
        } else {
          ok = false;
          break;
        }
      }
      if (ok) pnum += len;
      ok = true;
      temp = 0;
      for (j = str.size() - 1; j >= 0; j--) {
        if (str[j] == f_c) {
          temp += (len + 1);
          snum = max(snum, temp);
        } else {
          ok = false;
          break;
        }
      }
      if (ok) snum += len;
      temp = 0;
      long long len2 = len;
      for (int j = 0; j < str.size(); j++) {
        if (f_c == str[j]) {
          temp += len2 + 1;
        }
        if (j == str.size() - 1) {
          len = max(len, temp + len2);
        }
        if (f_c != str[j]) {
          len = max(len, temp + len2);
          temp = 0;
        }
      }
    } else {
      temp = 0;
      for (int j = 0; j < str.size(); j++) {
        if (str[j] == f_c && str[j] == l_c) {
          temp = pnum + snum + 1;
        } else if (str[j] == f_c) {
          temp = pnum + 1;
        } else if (str[j] == l_c) {
          temp = snum + 1;
        }
        len = max(len, temp);
      }
    }
    one &= one2;
  }
  cout << len;
}
