#include <bits/stdc++.h>
using namespace std;
int f[27][27];
char a[11];
int main() {
  int n;
  cin >> n;
  while (n--) {
    scanf("%s", a);
    int book = strlen(a), h = a[0] - 'a', t = a[book - 1] - 'a';
    for (int i = 0; i < 26; i++) {
      if (f[i][h]) f[i][t] = max(f[i][t], f[i][h] + book);
    }
    f[h][t] = max(f[h][t], book);
  }
  int book = 0;
  for (int i = 0; i < 26; i++) {
    book = max(book, f[i][i]);
  }
  cout << book;
}
