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