#include <bits/stdc++.h>
using namespace std;
int table[26][26] = {0};
int main() {
  int n, max = 0, head, tail, tmp;
  cin >> n;
  string word;
  while (n--) {
    cin >> word;
    head = word[0] - 'a';
    tail = word[word.length() - 1] - 'a';
    for (int i = 0; i < 26; ++i) {
      if (table[i][head] == 0) {
        continue;
      }
      tmp = table[i][head] + word.length();
      if (table[i][tail] < tmp) {
        table[i][tail] = tmp;
      }
    }
    if (table[head][tail] < word.length()) {
      table[head][tail] = word.length();
    }
  }
  for (int i = 0; i < 26; ++i) {
    max = max < table[i][i] ? table[i][i] : max;
  }
  cout << max << endl;
  return 0;
}
