#include <bits/stdc++.h>
using namespace std;
int n, ret, f[26];
vector<pair<pair<int, int>, int> > ss;
int call(char c) { return int(c) - int('a'); }
int main() {
  cin >> n;
  string s;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    ss.push_back(make_pair(make_pair(call(s[0]), call(s[long(s.length()) - 1])),
                           long(s.length())));
  }
  ret = 0;
  for (int c = 0; c < 26; c++) {
    fill(f + 0, f + 26, 0);
    for (int i = 0; i < n; i++) {
      if ((ss[i].first.first == c) || (f[ss[i].first.first] > 0)) {
        f[ss[i].first.second] =
            max(f[ss[i].first.second], f[ss[i].first.first] + ss[i].second);
      }
    }
    ret = max(ret, f[c]);
  }
  printf("%d", ret);
  return 0;
}
