#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
inline void chmin(A &a, B b) {
  if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b) {
  if (a < b) a = b;
}
long long N;
long long X[555555], Y[555555], L[555555];
char tmp[111];
signed main() {
  scanf("%lld", &N);
  for (long long i = 0; i < (N); i++) {
    scanf("%s", tmp);
    long long l = strlen(tmp);
    X[i] = tmp[0] - 'a';
    Y[i] = tmp[l - 1] - 'a';
    L[i] = l;
  }
  long long dp[26];
  long long ans = 0;
  for (long long i = 0; i < 26; i++) {
    fill_n(dp, 26, -100);
    dp[i] = 0;
    for (long long i = 0; i < N; i++) {
      chmax(dp[Y[i]], dp[X[i]] + L[i]);
    }
    chmax(ans, dp[i]);
  }
  cout << ans << endl;
  return 0;
}
