#include <bits/stdc++.h>
using namespace std;
const int N = 5 * 100000;
int dp[26][26];
int l[N], r[N];
int d[N];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    l[i] = s[0] - 'a';
    r[i] = s[s.length() - 1] - 'a';
    d[i] = s.length();
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++)
      if (dp[j][l[i]]) dp[j][r[i]] = max(dp[j][r[i]], dp[j][l[i]] + d[i]);
    dp[l[i]][r[i]] = max(dp[l[i]][r[i]], d[i]);
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, dp[i][i]);
  cout << ans;
  return 0;
}
