#include <bits/stdc++.h>
using namespace std;
const int maxn = 27;
int main() {
  char s[15];
  int n, a, b, len, ans = 0;
  cin >> n;
  int dp[maxn][maxn];
  memset(dp, 0, sizeof(dp));
  while (n--) {
    scanf("%s", &s);
    len = strlen(s);
    a = s[0] - 'a';
    b = s[len - 1] - 'a';
    for (int i = 0; i < 26; i++) {
      if (dp[i][a] && dp[i][a] + len > dp[i][b]) dp[i][b] = dp[i][a] + len;
    }
    dp[a][b] = max(dp[a][b], len);
  }
  for (int i = 0; i < 26; i++) {
    ans = max(ans, dp[i][i]);
  }
  cout << ans << endl;
  return 0;
}
