#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 5e5 + 5;
int dp[26][26];
int fir[MAXN];
int last[MAXN];
int l[MAXN];
bool is[26][26];
char str[20];
int main() {
  int n;
  scanf("%d ", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", str + 1);
    int len = strlen(str + 1);
    fir[i] = str[1];
    last[i] = str[len];
    l[i] = len;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 26; j++) {
      if (is[j][fir[i] - 'a']) {
        dp[j][last[i] - 'a'] =
            max(dp[j][last[i] - 'a'], dp[j][fir[i] - 'a'] + l[i]);
        is[j][last[i] - 'a'] = true;
      }
    }
    is[fir[i] - 'a'][last[i] - 'a'] = true;
    dp[fir[i] - 'a'][last[i] - 'a'] =
        max(l[i], dp[fir[i] - 'a'][last[i] - 'a']);
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, dp[i][i]);
  cout << ans << endl;
  return 0;
}
