#include <bits/stdc++.h>
using namespace std;
char s[555555][11];
int l[555555];
int last[26];
int n, ans;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s[i]);
    l[i] = (int)strlen(s[i]);
  }
  for (char fst = 'a'; fst <= 'z'; ++fst) {
    memset(last, -1, sizeof(last));
    for (int i = 0; i < n; ++i) {
      int f = -1;
      if (s[i][0] == fst) {
        f = l[i];
      }
      if (last[s[i][0] - 'a'] != -1) {
        f = l[i] + last[s[i][0] - 'a'];
      }
      if (s[i][l[i] - 1] == fst) {
        ans = max(ans, f);
      }
      if (f != -1)
        last[s[i][l[i] - 1] - 'a'] = max(last[s[i][l[i] - 1] - 'a'], f);
    }
  }
  cout << ans << endl;
}
