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