#include <bits/stdc++.h>
using namespace std;
int f[26][26];
char s[12];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%s", s);
    int len = strlen(s);
    int first = s[0] - 'a';
    int last = s[len - 1] - 'a';
    for (int be = 0; be < 26; be++) {
      if (f[be][first] == 0) continue;
      f[be][last] = max(f[be][last], f[be][first] + len);
    }
    f[first][last] = max(f[first][last], len);
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) {
    ans = max(ans, f[i][i]);
  }
  printf("%d", ans);
  return 0;
}
