#include <bits/stdc++.h>
using namespace std;
long long int mod = LLONG_MAX;
long long int power(long long int a, long long int b) {
  if (b == 0) return 1;
  long long int ans = power(a, b / 2);
  ans = (ans * ans) % mod;
  if (b % 2) ans *= a;
  return ans % mod;
}
auto start = chrono::high_resolution_clock::now();
vector<vector<vector<int> > > dp;
vector<string> v;
int solve(int idx, int l, int r) {
  if (idx == v.size()) {
    if (l == r) return 0;
    return -1;
  }
  if (dp[idx][l][r] != -2) return dp[idx][l][r];
  dp[idx][l][r] = -1;
  int sub_ans;
  if (l == 0) {
    sub_ans = solve(idx + 1, (v[idx][0] - 'a') + 1, (v[idx].back() - 'a') + 1);
    if (sub_ans != -1) dp[idx][l][r] = sub_ans + v[idx].size();
    sub_ans = solve(idx + 1, l, r);
    if (sub_ans != -1) dp[idx][l][r] = max(dp[idx][l][r], sub_ans);
    return dp[idx][l][r];
  }
  if (r == (v[idx][0] - 'a') + 1) {
    sub_ans = solve(idx + 1, l, (v[idx].back() - 'a') + 1);
    if (sub_ans != -1) dp[idx][l][r] = sub_ans + v[idx].size();
  }
  sub_ans = solve(idx + 1, l, r);
  if (sub_ans != -1) dp[idx][l][r] = max(dp[idx][l][r], sub_ans);
  return dp[idx][l][r];
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(NULL);
  cin.tie(NULL);
  int n;
  bool toggle = 0;
  cin >> n;
  dp.assign(2, vector<vector<int> >(27, vector<int>(27, 0)));
  v.assign(n, "");
  for (int i = 1; i <= n; i++) cin >> v[i - 1];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 27; j++) {
      for (int k = 0; k < 27; k++) dp[1 - toggle][j][k] = dp[toggle][j][k];
    }
    dp[1 - toggle][v[i][0] - 'a' + 1][v[i].back() - 'a' + 1] =
        max((int)v[i].size(),
            dp[1 - toggle][v[i][0] - 'a' + 1][v[i].back() - 'a' + 1]);
    for (int j = 1; j < 27; j++) {
      for (int k = 1; k < 27; k++) {
        if (k == v[i][0] - 'a' + 1 && dp[toggle][j][k] != 0)
          dp[1 - toggle][j][v[i].back() - 'a' + 1] =
              max(dp[1 - toggle][j][v[i].back() - 'a' + 1],
                  dp[toggle][j][k] + (int)v[i].size());
      }
    }
    toggle = 1 - toggle;
  }
  int ans = 0;
  for (int i = 1; i < 27; i++) ans = max(ans, dp[toggle][i][i]);
  cout << ans;
}
