#include <bits/stdc++.h>
using namespace std;
const double kEps = 10e-6;
const int kInf = 1000000000;
const int kLimit = 100;
int dp[27][27];
void read_line(char *buffer) {
  int ch, size = 0;
  while ((ch = getchar()) != '\n') buffer[size++] = ch;
  buffer[size] = '\0';
}
int main(int argc, char *argv[]) {
  char name[15];
  int n, i, j, l;
  scanf("%d\n", &n);
  for (i = 0; i < n; i++) {
    read_line(name);
    l = strlen(name);
    for (j = 'a'; j <= 'z'; j++) {
      if (dp[j - 'a'][name[0] - 'a'] || j == name[0])
        dp[j - 'a'][name[l - 1] - 'a'] =
            max(dp[j - 'a'][name[l - 1] - 'a'], dp[j - 'a'][name[0] - 'a'] + l);
    }
  }
  int max = 0;
  for (i = 0; i < 26; i++) max = std::max(max, dp[i][i]);
  cout << max << endl;
  return EXIT_SUCCESS;
}
