#include <bits/stdc++.h>
using namespace std;
void setmax(int &a, int b) {
  if (b > a) a = b;
}
int maxlen[26][26];
int a(string &s) { return s[0] - 'a'; }
int b(string &s) { return s[s.size() - 1] - 'a'; }
int buf[26];
int main() {
  for (int i = 0; i < 26; i++)
    for (int j = 0; j < 26; j++) maxlen[i][j] = -1 << 29;
  int n;
  cin >> n;
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int j = 0; j < 26; j++) buf[j] = maxlen[j][a(s)];
    for (int j = 0; j < 26; j++) {
      setmax(maxlen[j][b(s)], buf[j] + s.size());
    }
    setmax(maxlen[a(s)][b(s)], s.size());
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) {
    setmax(ans, maxlen[i][i]);
  }
  cout << ans << endl;
}
