#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
const int C = 26;
int n, m[N], f[C][C] = {0};
pair<int, int> a[N];
char s[N];
int main() {
  int ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int u, v;
    scanf("%s", s + 1);
    m[i] = strlen(s + 1);
    u = s[1] - 'a';
    v = s[m[i]] - 'a';
    if (u == v) ans = max(ans, m[i]);
    for (int fi = 0; fi < C; ++fi)
      if (f[fi][u] > 0) f[fi][v] = max(f[fi][v], f[fi][u] + m[i]);
    f[u][v] = max(f[u][v], m[i]);
    ans = max(ans, f[v][v]);
  }
  cout << ans;
  return 0;
}
