#include <bits/stdc++.h>
using namespace std;
string x[100009];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x[i];
  }
  int l = 0, r = 0;
  int ans = 1;
  char L = x[n][0], R = x[n][x[n].length() - 1];
  int co = 1;
  for (int i = 1; i < x[n].length(); i++) {
    if (x[n][i] == x[n][i - 1])
      co++;
    else {
      ans = max(ans, co);
      co = 1;
    }
  }
  ans = max(ans, co);
  int sum = 0;
  if (x[n].length() == 1) {
    sum = 1;
  } else {
    int i;
    for (i = 1; i < x[n].length(); i++) {
      if (x[n][i] != x[n][0]) break;
    }
    i--;
    if (i == x[n].length() - 1) {
      sum = x[n].length();
    } else {
      l = i + 1;
      for (i = x[n].length() - 2;; i--) {
        if (x[n][i] != R) break;
      }
      r = x[n].length() - 1 - i;
    }
  }
  ans = max(ans, max(sum, max(l, r)));
  for (int i = n - 1; i >= 1; i--) {
    if (!l) {
      int f = 0;
      for (int j = 0; j < x[i].length(); j++) {
        if (x[i][j] != L) {
          f = 1;
          l = j + (j + 1) * sum;
          break;
        }
      }
      if (f) {
        for (int j = x[i].length() - 1;; j--) {
          if (x[i][j] != R) {
            r = x[i].length() - 1 - j;
            r = r + (r + 1) * sum;
            break;
          }
        }
        int co = 0;
        for (int j = 0; j < x[i].length(); j++) {
          if (x[i][j] == L)
            co++;
          else {
            ans = max(ans, co + (co + 1) * sum);
            co = 0;
          }
        }
        ans = max(ans, co + (co + 1) * sum);
      } else {
        sum = x[i].length() + (x[i].length() + 1) * sum;
      }
    } else {
      for (int j = 0; j < x[i].length(); j++) {
        if (x[i][j] == L) {
          if (L == R) {
            ans = max(ans, l + r + 1);
          } else {
            ans = max(ans, l + 1);
          }
        } else if (x[i][j] == R) {
          ans = max(ans, r + 1);
        }
      }
    }
  }
  ans = max(ans, max(sum, max(l, r)));
  printf("%d\n", ans);
}
