#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
using namespace std;
long double EPS = 1e-10;
string a[500000];
char buf[11];
int A[26];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", buf);
    a[i] = buf;
  }
  int res = -1000000000;
  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < 26; j++) {
      A[j] = -1000000000;
    }
    A[i] = 0;
    for (int j = 0; j < n; j++) {
      A[a[j][a[j].length() - 1] - 'a'] =
          max(A[a[j][a[j].length() - 1] - 'a'],
              A[a[j][0] - 'a'] + (int)a[j].length());
    }
    res = max(res, A[i]);
  }
  cout << res << endl;
}
