#include <bits/stdc++.h>
using namespace std;
const int INFint = 2147483647;
const long long INF = 9223372036854775807ll;
const long long MOD = 1000000007ll;
const long double EPS = 1e-9;
long long d[500][500];
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    int l = s.length();
    for (int i = 'a'; i <= 'z'; i++) {
      if (d[i][s[0]] || i == s[0])
        d[i][s[l - 1]] = max(d[i][s[l - 1]], d[i][s[0]] + l);
    }
  }
  long long ans = 0;
  for (int i = 'a'; i <= 'z'; i++) ans = max(ans, d[i][i]);
  cout << ans << endl;
  fprintf(stderr, "\nTIME = %lf\n", 1.0 * clock() / CLOCKS_PER_SEC);
  return 0;
}
