#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
int n;
int m;
pair<int, int> g[500000];
int res[26];
int w[500000];
int main() {
  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    char s[15];
    scanf("%s\n", s);
    int m = strlen(s);
    g[i].first = s[0] - 'a';
    g[i].second = s[m - 1] - 'a';
    w[i] = m;
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < 26; j++) res[j] = -1e9;
    res[i] = 0;
    for (int j = 0; j < n; j++) {
      res[g[j].second] = max(res[g[j].second], res[g[j].first] + w[j]);
      if (g[j].second == i) ans = max(ans, res[g[j].second]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
