#include <bits/stdc++.h>
using namespace std;
int dp[27][27], a[101], c, k, ans;
char b[11];
int main() {
  cin >> c;
  getchar();
  for (int yui = 1; yui <= c; yui++) {
    scanf("%s", &b);
    k = strlen(b);
    a[0] = b[0] - 'a';
    a[k - 1] = b[k - 1] - 'a';
    for (int yui = 0; yui < 26; yui++) {
      if (dp[yui][a[0]] != 0)
        dp[yui][a[k - 1]] = max(dp[yui][a[0]] + k, dp[yui][a[k - 1]]);
    }
    dp[a[0]][a[k - 1]] = max(dp[a[0]][a[k - 1]], k);
  }
  for (int yui = 0; yui <= 25; yui++)
    if (dp[yui][yui] >= ans) ans = dp[yui][yui];
  cout << ans;
}
