#include <bits/stdc++.h>
using namespace std;
const int M = 1e6;
int main() {
  int n;
  int lol[26][26];
  for (int i = 0; i < 26; i++)
    for (int j = 0; j < 26; j++) lol[i][j] = 0;
  cin >> n;
  string s;
  int x, y;
  for (int i = 0; i < n; i++) {
    cin >> s;
    x = s[0] - 'a';
    y = s[s.size() - 1] - 'a';
    for (int c = 0; c < 26; c++) {
      if (lol[c][x]) lol[c][y] = max(lol[c][y], lol[c][x] + (int)s.size());
    }
    lol[x][y] = max(lol[x][y], (int)s.size());
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, lol[i][i]);
  cout << ans;
}
