#include <bits/stdc++.h>
using namespace std;
int f[110][110], n, s, e, l, r;
char a[110];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%s", &a);
    e = strlen(a);
    l = a[0] - 'a';
    r = a[e - 1] - 'a';
    for (int j = 0; j < 26; j++)
      if (f[j][l]) f[j][r] = max(f[j][r], f[j][l] + e);
    f[l][r] = max(f[l][r], e);
  }
  for (int i = 0; i < 26; i++) s = max(s, f[i][i]);
  cout << s;
  return 0;
}
