#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int dp[30][30], N;
string s;
const int oo = 1000000000;
int main() {
  while (cin >> N) {
    for (int i = 0; i < 30; i++) {
      for (int j = 0; j < 30; j++) {
        dp[i][j] = -oo;
      }
    }
    for (int i = 0; i < N; i++) {
      cin >> s;
      int a = int(s[0] - 'a'), b = int(s[s.size() - 1] - 'a'), l = s.size();
      for (int i = 0; i < 30; i++) {
        dp[i][b] = max(dp[i][b], dp[i][a] + l);
      }
      dp[a][b] = max(dp[a][b], l);
    }
    int res = -oo;
    for (int i = 0; i < 30; i++) {
      res = max(res, dp[i][i]);
    }
    cout << (res > 0 ? res : 0) << endl;
  }
}
