#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int N = (int)5e5 + 7;
const long long MOD = (long long)2e15 + 7;
const int P = 26;
int dp[N][P];
string a[N];
int get_max[P][P];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    int back = a[i].back() - 'a';
    int front = a[i].front() - 'a';
    int len = int(a[i].size());
    dp[i][front] = len;
    for (int j = 0; j < P; j++) {
      if (get_max[front][j]) dp[i][j] = max(dp[i][j], get_max[front][j] + len);
      get_max[back][j] = max(get_max[back][j], dp[i][j]);
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int back = a[i].back() - 'a';
    ans = max(ans, dp[i][back]);
  }
  cout << ans;
  return 0;
}
