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