#include <bits/stdc++.h>
using namespace std;
int d[26][26];
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int Max = 0;
  string s;
  int start, end;
  for (int k = 0; k < n; k++) {
    cin >> s;
    start = int(s[0] - 'a');
    end = int(s[s.length() - 1] - 'a');
    for (int i = 0; i < 26; i++)
      if (d[i][start] != 0)
        d[i][end] = max(d[i][end], d[i][start] + (int)s.length());
    d[start][end] = max(d[start][end], (int)s.length());
  }
  for (int k = 0; k < 26; k++) Max = max(Max, d[k][k]);
  cout << Max << endl;
  return 0;
}
