#include <bits/stdc++.h>
using namespace std;
long long f[210][210];
long long n, m, c0, d0;
char s[500080][12];
long long lennow, q, h;
int main() {
  cin >> n;
  memset(f, 0, sizeof f);
  for (int i = 1; i <= n; i++) {
    scanf("%s", &s[i]);
  }
  for (int i = 1; i <= n; i++) {
    lennow = strlen(s[i]);
    q = s[i][0] - 'a' + 1, h = s[i][lennow - 1] - 'a' + 1;
    f[0][q] = 1;
    for (int j = 1; j <= 26; j++) {
      if (f[j][q] == 0)
        continue;
      else {
        f[j][h] = max(f[j][h], f[j][q] + lennow);
      }
    }
    f[q][h] = max(f[q][h], lennow);
  }
  long long ans = 0;
  for (int i = 1; i <= 26; i++) {
    ans = max(ans, f[i][i]);
  }
  cout << ans;
  return 0;
}
