#include <bits/stdc++.h>
using namespace std;
const int N = 5e5;
int n, len[N], dp[N], nxt[N][26], B, vis[N], vs;
char s[N][11];
int calc(int at) {
  if (at == n) return -2e9;
  int &res = dp[at];
  if (vis[at] == vs) return res;
  vis[at] = vs;
  res = -2e9;
  if (s[at][len[at] - 1] - 'a' == B) res = len[at];
  res = max(res, calc(nxt[at][s[at][0] - 'a']));
  res = max(res, calc(nxt[at][s[at][len[at] - 1] - 'a']) + len[at]);
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s[i]);
    len[i] = strlen(s[i]);
  }
  int at[26];
  for (int i = 0; i < 26; ++i) at[i] = n;
  for (int i = n - 1; i >= 0; --i) {
    for (int j = 0; j < 26; ++j) nxt[i][j] = at[j];
    at[s[i][0] - 'a'] = i;
  }
  int res = 0;
  for (int i = 0; i < 26; ++i) {
    ++vs;
    B = i;
    res = max(res, calc(at[i]));
  }
  printf("%d\n", res);
  return 0;
}
