#include <bits/stdc++.h>
using namespace std;
int n, i, j, ans = 0, f[30][30], h, t, l;
char st[20];
int main() {
  scanf("%d\n", &n);
  memset(f, 0, sizeof(f));
  while (n--) {
    gets(st);
    l = strlen(st);
    h = (int)st[0] - 97;
    t = (int)st[l - 1] - 97;
    for (i = 0; i < 26; i++)
      if (f[i][h] && (f[i][t] < f[i][h] + l)) {
        f[i][t] = f[i][h] + l;
        if (t == i && ans < f[i][t]) ans = f[i][t];
      }
    if (f[h][t] < l) {
      f[h][t] = l;
      if (t == h) ans = max(ans, l);
    }
  }
  printf("%d\n", ans);
}
