#include <bits/stdc++.h>
using namespace std;
const int maxn = 30;
int dp[maxn][maxn], a, b;
char s[maxn];
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    int len = strlen(s);
    a = s[0] - 'a';
    b = s[len - 1] - 'a';
    for (int i = 0; i < 26; i++) {
      if (dp[i][a] && dp[i][a] + len > dp[i][b]) dp[i][b] = dp[i][a] + len;
    }
    if (dp[a][b] < len) dp[a][b] = len;
  }
  int ans = -1;
  for (int i = 0; i < 26; i++) {
    ans = max(ans, dp[i][i]);
  }
  cout << ans << endl;
  return 0;
}
