#include <bits/stdc++.h>
using namespace std;
const int infinity = 1e9 + 9;
int N;
string s;
int dpO[29][29];
int dpN[29][29];
int main() {
  for (int c = 0; c <= 'z' - 'a'; c++)
    for (int d = 0; d <= 'z' - 'a'; d++) dpO[c][d] = 0;
  cin >> N;
  getline(cin, s);
  for (int i = 0; i < N; i++) {
    getline(cin, s);
    int L = s.length();
    int a = s[0] - 'a';
    int b = s[L - 1] - 'a';
    for (int c = 0; c <= 'z' - 'a'; c++)
      for (int d = 0; d <= 'z' - 'a'; d++) dpN[c][d] = dpO[c][d];
    dpN[a][b] = max(dpN[a][b], L);
    for (int c = 0; c <= 'z' - 'a'; c++)
      if (dpN[c][b] < dpO[c][a] + L && dpO[c][a] > 0) dpN[c][b] = dpO[c][a] + L;
    for (int c = 0; c <= 'z' - 'a'; c++)
      for (int d = 0; d <= 'z' - 'a'; d++) dpO[c][d] = dpN[c][d];
  }
  int ans = 0;
  for (int c = 0; c <= 'z' - 'a'; c++) ans = max(ans, dpO[c][c]);
  cout << ans << endl;
  return 0;
}
