#include <bits/stdc++.h>
using namespace std;
int n, dp[200][200], ans;
string a;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    cin >> a;
    int c = a[a.length() - 1], c2 = a[0];
    for (int i = 'a'; i <= 'z'; ++i)
      if (dp[i][c2] > 0) dp[i][c] = max(dp[i][c], dp[i][c2] + (int)a.length());
    dp[c2][c] = max(dp[c2][c], (int)a.length());
  }
  for (int i = 'a'; i <= 'z'; ++i) ans = max(ans, dp[i][i]);
  printf("%d ", ans);
}
