#include <bits/stdc++.h>
using namespace std;
long long inf = 1e18;
const long long N = 3e5 + 5;
long long mod = 1e9 + 7;
long long dp[30][30];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long tt = 1;
  while (tt--) {
    long long n;
    cin >> n;
    string s;
    long long ans = 0;
    for (long long i = 0; i < n; i++) {
      cin >> s;
      long long ns = s.size();
      long long l = s[0] - 'a', r = s[ns - 1] - 'a';
      for (long long i = 0; i < 26; ++i) {
        if (dp[i][l]) {
          dp[i][r] = max(dp[i][r], dp[i][l] + ns);
        }
      }
      dp[l][r] = max(dp[l][r], ns);
      ans = max(ans, dp[r][r]);
    }
    cout << ans << '\n';
  }
  return 0;
}
