#include <bits/stdc++.h>
using namespace std;
void Weapons19() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int32_t main() {
  Weapons19();
  long long n;
  cin >> n;
  vector<vector<long long>> v(26, vector<long long>(26, 0));
  for (long long i = 0; i < n; i++) {
    string s;
    cin >> s;
    long long f = s[0] - 97;
    long long r = s[s.size() - 1] - 97;
    for (long long j = 0; j < 26; j++) {
      if (j == f && f == r) {
        v[f][r] += s.size();
        continue;
      }
      if (j == f && v[j][r] < s.size()) {
        v[f][r] = s.size();
      }
      if (v[j][f] + s.size() > v[j][r] && v[j][f] != 0) {
        v[j][r] = v[j][f] + s.size();
      }
    }
  }
  long long ans = 0;
  for (long long i = 0; i < 26; i++) {
    ans = max(ans, v[i][i]);
  }
  cout << ans;
}
