#include <bits/stdc++.h>
using namespace std;
int dp[26][26];
int main() {
  int N;
  cin >> N;
  memset(dp, 0, sizeof(dp));
  int res = 0;
  for (int i = 0; i < N; i++) {
    string n;
    cin >> n;
    int S = n.size();
    int F = n[0] - 'a';
    int L = n[S - 1] - 'a';
    for (int i = 0; i < 26; i++) {
      if (dp[i][F]) dp[i][L] = max(dp[i][L], dp[i][F] + S);
    }
    dp[F][L] = max(dp[F][L], S);
  }
  for (int i = 0; i < 26; i++) res = max(res, dp[i][i]);
  cout << res << endl;
}
