#include <bits/stdc++.h>
using namespace std;
const int oo = 1 << 20;
const double PI = M_PI;
const double EPS = 1e-15;
const int MaxN = 500001;
int n;
char s[MaxN][15];
int dp[26][26];
int main() {
  cin.sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) {
    int L = strlen(s[i]);
    int a = s[i][0] - 'a';
    int b = s[i][L - 1] - 'a';
    for (int j = 0; j < 26; j++)
      if (dp[j][a]) {
        dp[j][b] = max(dp[j][b], dp[j][a] + L);
      }
    dp[a][b] = max(dp[a][b], L);
  }
  int answer = 0;
  for (int i = 0; i < 26; i++) answer = max(answer, dp[i][i]);
  cout << answer << endl;
  return 0;
}
