#include <bits/stdc++.h>
using namespace std;
long long dp[26][26];
string s;
long long n, cd, ans, t, w;
int main() {
  cin >> n;
  memset(dp, -999999, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    cin >> s;
    cd = s.length();
    t = s[0] - 'a';
    w = s[cd - 1] - 'a';
    for (int j = 0; j < 26; j++) {
      if (dp[j][t] != -999999) {
        dp[j][w] = max(dp[j][w], dp[j][t] + cd);
      }
    }
    dp[t][w] = max(dp[t][w], cd);
  }
  for (int i = 0; i < 26; i++) {
    ans = max(ans, dp[i][i]);
  }
  cout << ans << endl;
  return 0;
}
