#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s, t;
  cin >> n;
  vector<vector<int> > DP(26, vector<int>(26, -10000000));
  for (int i = 0; i < n; i++) {
    t = s;
    cin >> s;
    if (i > 0)
      DP[t[0] - 'a'][t[t.length() - 1] - 'a'] =
          max(DP[t[0] - 'a'][t[t.length() - 1] - 'a'], (int)t.length());
    for (int j = 0; j < 26; j++)
      DP[j][s[s.length() - 1] - 'a'] = max(DP[j][s[s.length() - 1] - 'a'],
                                           DP[j][s[0] - 'a'] + (int)s.length());
  }
  t = s;
  DP[t[0] - 'a'][t[t.length() - 1] - 'a'] =
      max(DP[t[0] - 'a'][t[t.length() - 1] - 'a'], (int)t.length());
  int Ans = 0;
  for (int i = 0; i < 26; i++) Ans = max(Ans, DP[i][i]);
  cout << Ans;
  return 0;
}
