#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  vector<string> v(n, "mia_melona");
  for (long long int i = 0; i < n; i++) {
    cin >> v[i];
  }
  long long int dp[27][27] = {{0}, {0}};
  for (long long int i = 0; i < n; i++) {
    long long int sz = (long long int)v[i].size();
    long long int st = v[i][0] - 'a', ed = v[i][sz - 1] - 'a';
    for (long long int j = 0; j < 26; j++) {
      if (dp[j][st] != 0) {
        dp[j][ed] = max(dp[j][ed], dp[j][st] + sz);
      }
    }
    dp[st][ed] = max(dp[st][ed], sz);
  }
  long long int ans = 0;
  for (long long int i = 0; i < 26; i++) {
    ans = max(ans, dp[i][i]);
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  {
    solve();
    cout << "\n";
  }
}
