#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-10;
double pi = atan((double)1.0) * (double)4.0;
pair<double, double> rot(double x, double y, double a) {
  a = a * pi / 180.0;
  double x2 = x * cos(a) - y * sin(a);
  double y2 = x * sin(a) + y * cos(a);
  return pair<double, double>(x2, y2);
}
long long N;
vector<pair<int, int> > in;
vector<long long> len;
long long dp[27][27];
int main() {
  memset(dp, 0, sizeof(dp));
  cin >> N;
  in.resize(N);
  len.resize(N);
  for (int i = 0; i < N; ++i) {
    string s;
    cin >> s;
    in[i] = pair<int, int>(s[0] - 'a', s[s.length() - 1] - 'a');
    len[i] = s.length();
  }
  for (int j = 0; j < 27; ++j)
    for (int k = 0; k < 27; ++k) dp[j][k] = -1;
  long long result = 0;
  for (int i = 0; i < N; ++i) {
    for (int org = 0; org < 27; ++org) {
      if (dp[in[i].first][org] != -1) {
        dp[in[i].second][org] =
            max(dp[in[i].second][org], dp[in[i].first][org] + len[i]);
      } else {
      }
    }
    dp[in[i].second][in[i].first] = max(dp[in[i].second][in[i].first], len[i]);
    result = max(result, dp[in[i].second][in[i].second]);
  }
  cout << result;
}
