#include <bits/stdc++.h>
using namespace std;
int n, t1, t2, f[30][30];
char b[20];
struct node {
  int x, y, z;
} a[500005];
int main() {
  scanf("%d", &n);
  t1 = int('a');
  t2 = int('z');
  for (int i = 1; i <= n; i++) {
    scanf("%s", b);
    int p, sum;
    sum = 0;
    for (int j = 0; int(b[j]) >= t1 && int(b[j]) <= t2; j++) {
      p = int(b[j]) - t1 + 1;
      if (j == 0) a[i].x = p;
      sum++;
    }
    a[i].y = p;
    a[i].z = sum;
  }
  memset(f, 0, sizeof(f));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 26; j++)
      if (f[j][a[i].x] != 0)
        f[j][a[i].y] = max(f[j][a[i].y], f[j][a[i].x] + a[i].z);
    f[a[i].x][a[i].y] = max(f[a[i].x][a[i].y], a[i].z);
  }
  int ans = 0;
  for (int i = 1; i <= 26; i++) ans = max(ans, f[i][i]);
  cout << ans << endl;
  return 0;
}
