#include <bits/stdc++.h>
using namespace std;
double EPS = 1e-10;
double EQ(double a, double b) { return abs(a - b) < EPS; }
void fast_stream() { std::ios_base::sync_with_stdio(0); }
vector<string> strs;
int dp[2][31][31];
const int INF = 1000000000;
void solve() {
  fast_stream();
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    strs.push_back(s);
  }
  for (int i = n; i >= 0; i--) {
    int cur = i % 2;
    int nxt = (i + 1) % 2;
    for (int j = 0; j < 27; j++) {
      for (int k = 0; k < 27; k++) {
        int res = -INF;
        if (i == n) {
          if (k == j && k != 26)
            res = 0;
          else
            res = -INF;
        } else {
          if (strs[i][0] - 'a' == j || k == 26) {
            int nk = k;
            if (k == 26) nk = strs[i][0] - 'a';
            res = max(res, dp[nxt][strs[i][strs[i].size() - 1] - 'a'][nk] +
                               (int)strs[i].size());
          }
          res = max(res, dp[nxt][j][k]);
        }
        dp[cur][j][k] = res;
      }
    }
  }
  cout << max(0, dp[0][26][26]) << endl;
}
int main() {
  solve();
  return 0;
}
