#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int dp[26][26];
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < n; ++i) {
    char w[12];
    cin >> w;
    int f = w[0] - 'a';
    int l = w[strlen(w) - 1] - 'a';
    int s = strlen(w);
    for (int j = 0; j < 26; ++j) {
      if (dp[j][f]) dp[j][l] = max(dp[j][l], dp[j][f] + s);
    }
    dp[f][l] = max(dp[f][l], s);
  }
  int ans = 0;
  for (int i = 0; i < 26; ++i) ans = max(ans, dp[i][i]);
  cout << ans << endl;
}
