#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s;
  vector<vector<int> > M;
  cin >> n;
  M.resize(26);
  for (int i = 0; i < 26; ++i) {
    M[i].resize(26, 0);
  }
  for (int i = 0; i < n; ++i) {
    cin >> s;
    int size = (int)s.size();
    for (int j = 0; j < size; ++j) {
      s[j] -= 'a';
    }
    for (int j = 0; j < 26; ++j) {
      if (M[j][s[0]] != 0 && M[j][s[0]] + size > M[j][s[size - 1]]) {
        M[j][s[size - 1]] = M[j][s[0]] + size;
      }
    }
    if (size > M[s[0]][s[size - 1]]) {
      M[s[0]][s[size - 1]] = size;
    }
  }
  int res = 0;
  for (int i = 0; i < 26; ++i) {
    if (M[i][i] > res) {
      res = M[i][i];
    }
  }
  cout << res << endl;
  return 0;
}
