#include <bits/stdc++.h>
using namespace std;
struct grrr {
  long long mx[26], pref[26], suf[26];
  int ch;
  grrr(string s) {
    for (int i = 0; i < 26; ++i) {
      mx[i] = pref[i] = suf[i] = 0;
    }
    int i = 1;
    ++pref[s[0] - 'a'];
    ++suf[s[s.size() - 1] - 'a'];
    while (i < s.size() && s[i] == s[i - 1]) {
      ++pref[s[i] - 'a'];
      ++i;
    }
    if (i == s.size()) {
      ch = s[0] - 'a';
    } else {
      ch = -1;
    }
    i = int(s.size()) - 2;
    while (i >= 0 && s[i] == s[i + 1]) {
      ++suf[s[i] - 'a'];
      --i;
    }
    i = 1;
    long long len = 1;
    for (; i < s.size(); ++i) {
      mx[s[i - 1] - 'a'] = max(mx[s[i - 1] - 'a'], len);
      if (s[i] == s[i - 1]) {
        len++;
      } else {
        len = 1;
      }
    }
    mx[s[s.size() - 1] - 'a'] = max(mx[s[s.size() - 1] - 'a'], len);
  }
  void operator*=(grrr& g) {
    swap(g, *this);
    if (ch != -1 && g.ch != -1) {
      if (ch == g.ch) {
        long long len = mx[ch] * (g.mx[ch] + 1) + g.mx[ch];
        mx[ch] = pref[ch] = suf[ch] = len;
      } else {
        ch = -1;
        mx[g.ch] = g.mx[g.ch];
      }
      return;
    }
    if (ch != -1) {
      pref[ch] = (g.pref[ch] + 1) * mx[ch] + g.pref[ch];
      suf[ch] = (g.suf[ch] + 1) * mx[ch] + g.suf[ch];
      mx[ch] = (g.mx[ch] + 1) * mx[ch] + g.mx[ch];
      for (int i = 0; i < 26; ++i) {
        if (g.mx[i]) mx[i] = max(mx[i], 1ll);
      }
      ch = -1;
      return;
    }
    for (int i = 0; i < 26; ++i) {
      if (g.mx[i] > 0) {
        mx[i] = max(mx[i], pref[i] + suf[i] + 1);
        mx[i] = max(mx[i], 1ll);
      }
    }
  }
  long long get_max() {
    long long res = 0;
    for (int i = 0; i < 26; ++i) {
      res = max(res, mx[i]);
    }
    return res;
  }
};
int main() {
  int n;
  cin >> n;
  vector<string> p(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> p[i];
  }
  grrr now(p[1]);
  for (int i = 2; i <= n; ++i) {
    auto g = grrr(p[i]);
    now *= g;
  }
  cout << now.get_max();
}
