#include <bits/stdc++.h>
using namespace std;
int n, ans = 0;
int maxr[30][30];
char ch[20];
int main() {
  memset(maxr, -1, sizeof maxr);
  for (int i = 1; i <= 26; i++) maxr[i][i] = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", ch + 1);
    int x = ch[1] - 'a' + 1, y = ch[strlen(ch + 1)] - 'a' + 1;
    int len = strlen(ch + 1);
    for (int j = 1; j <= 26; j++)
      if (~maxr[j][x]) {
        maxr[j][y] = max(maxr[j][y], maxr[j][x] + len);
        if (j == y) ans = max(maxr[j][y], ans);
      }
  }
  printf("%d ", ans);
  return 0;
}
