#include <bits/stdc++.h>
int in() {
  int x;
  scanf("%d", &x);
  return x;
}
int main() {
  int n = in();
  int name['z' + 5]['z' + 5] = {0};
  while (n--) {
    char t[15];
    scanf("%s", &t);
    int l = strlen(t);
    char st = t[0], ed = t[l - 1];
    for (int i = 'a'; i <= 'z'; i++) {
      if (name[i][st] != 0 && name[i][ed] < name[i][st] + l) {
        name[i][ed] = name[i][st] + l;
      }
    }
    if (l > name[st][ed]) name[st][ed] = l;
  }
  int ans = 0;
  for (int i = 'a'; i <= 'z'; i++) {
    if (name[i][i] > ans) ans = name[i][i];
  }
  printf("%d\n", ans);
  return 0;
}
