#include <bits/stdc++.h>
using namespace std;
char c[500005][11];
int len[500005], d[27][27];
int main() {
  int n, i, j, k, jj;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> c[i];
    len[i] = strlen(c[i]);
  }
  for (i = 0; i < 27; i++)
    for (j = 0; j < 27; j++) d[i][j] = 0;
  for (k = 0; k < n; k++) {
    j = int(c[k][0] - 'a');
    jj = int(c[k][len[k] - 1] - 'a');
    for (i = 0; i < 27; i++)
      if (d[i][j] && d[i][jj] < d[i][j] + len[k]) d[i][jj] = d[i][j] + len[k];
    if (d[j][jj] < len[k]) d[j][jj] = len[k];
  }
  j = 0;
  for (i = 0; i < 27; i++)
    if (d[i][i] > j) j = d[i][i];
  cout << j;
  return 0;
}
