#include <bits/stdc++.h>
using namespace std;
int dp[26][26] = {0};
int str2num(char a) { return ((int)a - 97); }
int main() {
  char tmp[11];
  int n, s, e, l, sol = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", tmp);
    l = strlen(tmp);
    s = str2num(tmp[0]);
    e = str2num(tmp[l - 1]);
    for (int j = 0; j < 26; j++) {
      if (dp[j][s] != 0)
        if (dp[j][e] < dp[j][s] + l) {
          dp[j][e] = dp[j][s] + l;
        }
    }
    if (dp[s][e] < l) {
      dp[s][e] = l;
    }
  }
  for (int i = 0; i < 26; i++) {
    if (sol < dp[i][i]) {
      sol = dp[i][i];
    }
  }
  cout << sol << endl;
}
