#include <bits/stdc++.h>
using namespace std;
char temp[15];
char s[500005][3];
int a[500005], g[27][27];
bool r[27];
int ans, n;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", temp);
    if (strlen(temp) == 1)
      s[i][0] = s[i][1] = temp[0] - 'a';
    else {
      s[i][0] = temp[0] - 'a';
      s[i][1] = temp[strlen(temp) - 1] - 'a';
    }
    a[i] = strlen(temp);
  }
  memset(r, 0, sizeof(r));
  memset(g, 255, sizeof(g));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      int t;
      if (g[j][s[i][0]] != -1) {
        t = g[j][s[i][0]] + a[i];
        g[j][s[i][1]] = max(g[j][s[i][1]], t);
      }
    }
    g[s[i][0]][s[i][1]] = max(a[i], g[s[i][0]][s[i][1]]);
  }
  ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, g[i][i]);
  printf("%d\n", ans);
}
