#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void chkmax(T& x, U y) {
  if (x < y) x = y;
}
template <typename T, typename U>
inline void chkmin(T& x, U y) {
  if (y < x) x = y;
}
int f[26][26], g[26][26];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    char s[111];
    scanf("%s", s);
    int l = strlen(s);
    int c1 = s[0] - 'a', c2 = s[l - 1] - 'a';
    for (int j = 0; j < 26; j++) {
      g[j][c2] = 0;
      if (j == c1 || f[j][c1] != 0) {
        chkmax(g[j][c2], f[j][c1] + l);
      }
    }
    for (int j = 0; j < 26; j++) chkmax(f[j][c2], g[j][c2]);
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) chkmax(ans, f[i][i]);
  cout << ans << endl;
  return 0;
}
