#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500005;
const int MAXL = 15;
const int MAXK = 30;
int n;
char s[MAXN][MAXL];
int l[MAXN];
int a[MAXN], b[MAXN];
int f[MAXK][MAXK];
int main() {
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; i++) {
      scanf("%s", s[i]);
      l[i] = strlen(s[i]);
      a[i] = s[i][0] - 'a';
      b[i] = s[i][l[i] - 1] - 'a';
    }
    memset(f, -1, sizeof(f));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 26; j++) {
        if (f[j][a[i]] >= 0) {
          f[j][b[i]] = max(f[j][b[i]], f[j][a[i]] + l[i]);
        }
      }
      f[a[i]][b[i]] = max(f[a[i]][b[i]], l[i]);
    }
    int ans = 0;
    for (int i = 0; i < 26; i++) {
      ans = max(ans, f[i][i]);
    }
    printf("%d\n", ans);
  }
  return 0;
}
