#include <bits/stdc++.h>
using namespace std;
const int kMaxn = 500007;
int n, len, ans, d[30][30];
int main() {
  while (scanf("%d", &n) == 1) {
    ans = 0;
    memset(d, 0, sizeof(d));
    for (int i = 1; i <= n; i++) {
      char str[17];
      scanf("%s", str);
      len = strlen(str);
      for (int j = 0; j < 26; j++)
        if (d[j][str[0] - 'a'] > 0)
          d[j][str[len - 1] - 'a'] =
              max(d[j][str[len - 1] - 'a'], d[j][str[0] - 'a'] + len);
      d[str[0] - 'a'][str[len - 1] - 'a'] =
          max(len, d[str[0] - 'a'][str[len - 1] - 'a']);
    }
    for (int i = 0; i < 26; i++) ans = max(ans, d[i][i]);
    printf("%d\n", ans);
  }
  return 0;
}
