#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  long long int n;
  cin >> n;
  long long int dp[27][27] = {0};
  for (long long int i = 0; i < n; i++) {
    char ar[11];
    cin >> ar;
    long long int len = strlen(ar);
    long long int f = (long long int)(ar[0]) - 96;
    long long int l = (long long int)(ar[len - 1]) - 96;
    long long int temp = len;
    for (long long int i = 1; i <= 26; i++) {
      if (dp[i][f] != 0) dp[i][l] = max(dp[i][l], dp[i][f] + temp);
    }
    dp[f][l] = max(dp[f][l], len);
  }
  long long int maxi = 0;
  for (long long int i = 1; i <= 26; i++) {
    maxi = max(maxi, dp[i][i]);
  }
  cout << maxi;
  return 0;
}
