#include <bits/stdc++.h>
using namespace std;
const int pi = acos(-1.0);
const int N = 500000 + 3;
char ch[20];
int n;
int cnt[30][30];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  memset(cnt, -1, sizeof(cnt));
  for (int i = 0; i < 26; ++i) cnt[i][i] = 0;
  while (n--) {
    cin >> ch;
    int len = strlen(ch);
    int pre = ch[0] - 'a', last = ch[len - 1] - 'a';
    for (int i = 0; i < 26; ++i)
      if (cnt[i][pre] != -1)
        cnt[i][last] = max(cnt[i][last], cnt[i][pre] + len);
  }
  int m = 0;
  for (int i = 0; i < 26; ++i) m = max(cnt[i][i], m);
  cout << m << endl;
  return 0;
}
