#include <bits/stdc++.h>
using namespace std;
long long power(long long base, long long exp) {
  long long res = 1;
  while (exp > 0) {
    if (exp % 2 == 1) res = (res * base);
    base = (base * base);
    exp /= 2;
  }
  return res;
}
int main() {
  long long n;
  cin >> n;
  string arr[n];
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long ans = 0;
  for (long long i = 0; i < 26; i++) {
    long long cls[26];
    for (long long k = 0; k < 26; k++) {
      cls[k] = -1e18;
    }
    cls[i] = 0;
    for (long long j = 0; j < n; j++) {
      long long s = arr[j][0] - 'a';
      long long len = arr[j].length();
      long long e = arr[j][len - 1] - 'a';
      if (cls[s] >= 0) {
        cls[e] = max(cls[e], cls[s] + len);
      }
    }
    ans = max(ans, cls[i]);
  }
  cout << ans << "\n";
  return 0;
}
