#include <bits/stdc++.h>
using namespace std;
int mas[26][26], n;
char ss[500005][15];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) scanf("%s", &ss[i]);
  int l;
  for (int i = 0; i < n; ++i) {
    l = strlen(ss[i]);
    int pb = ss[i][0] - 'a';
    int pe = ss[i][l - 1] - 'a';
    for (int j = 0; j < 26; ++j) {
      if (mas[j][pb]) mas[j][pe] = max(mas[j][pe], mas[j][pb] + l);
    }
    mas[pb][pe] = max(mas[pb][pe], l);
  }
  int ans = 0;
  for (int i = 0; i < 26; ++i) ans = max(ans, mas[i][i]);
  cout << ans << endl;
  return 0;
}
