#include <bits/stdc++.h>
const int MAXN = 5e5 + 100;
int n, l[MAXN], r[MAXN], w[MAXN], f[26][26], flag[MAXN];
char s[MAXN];
inline int min(int a, int b) { return a < b ? a : b; }
inline int max(int a, int b) { return a > b ? a : b; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    int len = strlen(s + 1);
    l[i] = s[1] - 'a', r[i] = s[len] - 'a', w[i] = len;
  }
  std::memset(f, -1, sizeof(f));
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 25; j++) {
      if (f[j][l[i]] != -1) {
        f[j][r[i]] = max(f[j][r[i]], f[j][l[i]] + w[i]);
      }
    }
    f[l[i]][r[i]] = max(f[l[i]][r[i]], w[i]);
  }
  int ans = 0;
  for (int i = 0; i <= 25; i++) {
    ans = max(ans, f[i][i]);
  }
  printf("%d", ans);
  return 0;
}
