#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  int len[26][26];
  memset(len, 0, sizeof(len));
  int ans = 0;
  for (int i = 0; i < n; i++) {
    string all;
    cin >> all;
    int sz = all.size();
    char f = all[0];
    char d = all[sz - 1];
    for (int i = 0; i < 26; i++) {
      len[d - 'a'][i] = max(len[d - 'a'][i],
                            (len[f - 'a'][i] ? sz + len[f - 'a'][i]
                                             : (i == (int)f - 'a' ? sz : 0)));
    }
  }
  for (int i = 0; i < 26; i++) ans = max(ans, len[i][i]);
  cout << ans << endl;
}
