#include <bits/stdc++.h>
using namespace std;
FILE *in, *out;
pair<pair<int, int>, int> P[1000000];
int DP[250][250], N;
void read() {
  int sz;
  string temp;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> temp, sz = temp.size();
    P[i] = make_pair(make_pair(temp[0], temp[sz - 1]), sz);
  }
}
void solve() {
  int i, j, b, s, uz, res = 0;
  for (i = N; i >= 1; i--) {
    b = P[i].first.first;
    s = P[i].first.second;
    uz = P[i].second;
    for (j = 'a'; j <= 'z'; j++)
      if (DP[s][j])
        DP[b][j] =
            ((DP[b][j]) > (uz + DP[s][j]) ? (DP[b][j]) : (uz + DP[s][j]));
    DP[b][s] = ((DP[b][s]) > (uz) ? (DP[b][s]) : (uz));
  }
  for (i = 'a'; i <= 'z'; i++) {
    res = ((res) > (DP[i][i]) ? (res) : (DP[i][i]));
  }
  cout << res << endl;
}
int main() {
  read();
  solve();
}
