#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  const int maxn = 30;
  vector<vector<int>> dp(maxn, vector<int>(maxn));
  int n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    int u = s[0] - 'a', v = s[s.length() - 1] - 'a';
    for (int i = 0; i < maxn; ++i)
      if (dp[i][u]) dp[i][v] = max(dp[i][v], dp[i][u] + (int)s.length());
    dp[u][v] = max(dp[u][v], (int)s.length());
  }
  int ans = 0;
  for (int i = 0; i < maxn; ++i) ans = max(ans, dp[i][i]);
  cout << ans << '\n';
  return 0;
}
