#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int name['z' + 5]['z' + 5] = {0};
  while (n--) {
    string t;
    cin >> t;
    int l = t.length();
    char st = t[0], ed = t[l - 1];
    for (int i = 'a'; i <= 'z'; i++) {
      if (name[i][st] != 0) {
        name[i][ed] = max(name[i][ed], name[i][st] + l);
      }
    }
    name[st][ed] = max(name[st][ed], l);
  }
  int ans = 0;
  for (int i = 'a'; i <= 'z'; i++) {
    ans = max(ans, name[i][i]);
  }
  cout << ans << endl;
}
