#include <bits/stdc++.h>
using namespace std;
vector<string> a;
string s;
int n, ans, f, l, len;
int dp[150][150];
int main() {
  scanf("%d\n", &n);
  for (int i = 1; i <= n; i++) {
    getline(cin, s);
    a.push_back(s);
  }
  for (int i = 0; i < (int)a.size(); i++) {
    len = (int)a[i].length();
    f = (int)a[i][0];
    l = (int)a[i][len - 1];
    for (int j = 'a'; j <= 'z'; j++)
      if (dp[j][f] != 0) dp[j][l] = max(dp[j][l], dp[j][f] + len);
    dp[f][l] = max(dp[f][l], len);
  }
  ans = 0;
  for (int i = 'a'; i <= 'z'; i++) ans = max(ans, dp[i][i]);
  cout << ans;
  return 0;
}
