#include <bits/stdc++.h>
using namespace std;
int dp[30][30];
char buf[30];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%s", buf);
    int len = (int)strlen(buf);
    int st = buf[0] - 'a';
    int ed = buf[len - 1] - 'a';
    for (int j = 0; j < 26; j++)
      if (dp[j][st] > 0 && dp[j][st] + len > dp[j][ed])
        dp[j][ed] = dp[j][st] + len;
    if (dp[st][ed] < len) dp[st][ed] = len;
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, dp[i][i]);
  cout << ans << endl;
}
