#include <bits/stdc++.h>
using namespace std;
void boost() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
}
int main() {
  boost();
  int n;
  cin >> n;
  vector<string> a;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    a.push_back(s);
  }
  long dp[26][26] = {};
  for (int i = 0; i < n; i++) {
    int start = a[i][0] - 'a';
    int end = a[i][a[i].size() - 1] - 'a';
    for (int j = 0; j < 26; j++) {
      if (dp[j][start]) {
        dp[j][end] = max(dp[j][end], dp[j][start] + (long)a[i].size());
      }
    }
    dp[start][end] = max(dp[start][end], (long)a[i].size());
  }
  long mx = 0;
  for (int i = 0; i < 26; i++) {
    mx = max(mx, dp[i][i]);
  }
  cout << mx;
}
