#include <bits/stdc++.h>
using namespace std;
int n, dp[30][30];
string a[500000 + 10];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    int u = a[i][0] - 'a';
    int v = a[i][a[i].size() - 1] - 'a';
    for (int j = 0; j < 26; j++) {
      if (dp[j][u] == 0) continue;
      dp[j][v] = max(dp[j][v], dp[j][u] + (int)a[i].size());
    }
    dp[u][v] = max(dp[u][v], (int)a[i].size());
  }
  int res = 0;
  for (int i = 0; i < 26; i++) {
    res = max(res, dp[i][i]);
  }
  cout << res << "\n";
}
