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