#include <bits/stdc++.h>
using namespace std;
int n, dp[26][26];
char input[100];
int main() {
  cin >> n;
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    cin >> input;
    int l = strlen(input), h = input[0] - 'a', t = input[l - 1] - 'a';
    for (int i = 0; i < 26; i++)
      if (dp[i][h] != -1) dp[i][t] = max(dp[i][t], dp[i][h] + l);
    dp[h][t] = max(dp[h][t], l);
  }
  int res = 0;
  for (int i = 0; i < 26; i++) res = max(res, dp[i][i]);
  cout << res << endl;
  return 0;
}
