#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int>> DP;
vector<pair<int, int>> words;
vector<int> w;
vector<vector<int>> invw(26);
vector<int> inv2w;
vector<int> inv3w;
int f(int c, int i) {
  if (DP[c][i] != -1) return DP[c][i];
  int total = (int)-1e9;
  if (words[i].second == c) total = w[i];
  if (inv2w[i] < invw[words[i].second].size()) {
    total = max(total, f(c, invw[words[i].second][inv2w[i]]) + w[i]);
  }
  if (inv3w[i] < invw[words[i].first].size()) {
    total = max(total, f(c, invw[words[i].first][inv3w[i]]));
  }
  return DP[c][i] = total;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  string s;
  words.assign(n, make_pair(0, 0));
  w.assign(n, 0);
  DP.assign(26, vector<int>(n, -1));
  inv2w.assign(n, 0);
  inv3w.assign(n, 0);
  for (int i = 0; i < (int)n; i++) {
    cin >> s;
    words[i] = make_pair(s[0] - 'a', s[s.size() - 1] - 'a');
    w[i] = s.size();
    invw[s[0] - 'a'].emplace_back(i);
    inv2w[i] = invw[s[s.size() - 1] - 'a'].size();
    inv3w[i] = invw[s[0] - 'a'].size();
  }
  int M = 0;
  for (int i = 0; i < (int)n; i++) {
    M = max(M, f(words[i].first, i));
  }
  cout << M << '\n';
}
