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