#include <bits/stdc++.h>
using namespace std;
int d[26][26];
int main() {
  for (char ch1 = 'a'; ch1 <= 'z'; ch1++) {
    for (char ch2 = 'a'; ch2 <= 'z'; ch2++) {
      d[ch1 - 'a'][ch2 - 'a'] = -(1 << 30);
    }
  }
  int n, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (char ch = 'a'; ch <= 'z'; ch++) {
      d[ch - 'a'][s[s.length() - 1] - 'a'] =
          max(d[ch - 'a'][s[s.length() - 1] - 'a'],
              d[ch - 'a'][s[0] - 'a'] + (int)s.length());
    }
    d[s[0] - 'a'][s[s.length() - 1] - 'a'] =
        max(d[s[0] - 'a'][s[s.length() - 1] - 'a'], (int)s.length());
  }
  for (char ch = 'a'; ch <= 'z'; ch++) {
    ans = max(ans, d[ch - 'a'][ch - 'a']);
  }
  cout << ans;
}
