#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const long long INF = 1e18;
int n;
int dp[27][27];
int main() {
  cin >> n;
  char second[15];
  gets(second);
  for (int i = 0; i < n; i++) {
    gets(second);
    int ln = strlen(second), cs = second[0] - 'a', ce = second[ln - 1] - 'a';
    for (int j = 0; j < 26; j++)
      if (dp[j][cs]) dp[j][ce] = max(dp[j][ce], dp[j][cs] + ln);
    dp[cs][ce] = max(dp[cs][ce], ln);
  }
  int ans = 0;
  for (int j = 0; j < 26; j++) ans = max(ans, dp[j][j]);
  cout << ans << endl;
  return 0;
}
