#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long N = 2e5 + 7;
const int mod = 1e9 + 7;
long long dp[26][26];
void solve() {
  long long n;
  cin >> n;
  long long res = INT_MIN;
  for (long long i = 0; i < n; i++) {
    string s;
    cin >> s;
    long long start = s[0] - 'a';
    long long length = s.length();
    long long end = s[s.length() - 1] - 'a';
    for (long long i = 0; i < 26; i++) {
      if (dp[i][start]) {
        dp[i][end] = max(dp[i][end], dp[i][start] + length);
      }
    }
    dp[start][end] = max(dp[start][end], length);
  }
  for (long long i = 0; i < 26; i++) {
    for (long long j = 0; j < 26; j++) {
      res = max(res, dp[i][i]);
    }
  }
  cout << res << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
}
