#include <bits/stdc++.h>
using namespace std;
ifstream fin;
ofstream fout;
FILE *outt, *inn;
int n;
int dp[27][27];
char ch[20];
int main() {
  fin.open("1.txt");
  cin >> n;
  memset(dp, 0, sizeof(dp));
  for (int r = 1; r <= n; r++) {
    scanf("%s", ch);
    int len = strlen(ch);
    for (int i = 1; i <= 26; i++) {
      if (dp[i][ch[0] - 'a' + 1] > 0 || (i == ch[0] - 'a' + 1))
        dp[i][ch[len - 1] - 'a' + 1] =
            max(dp[i][ch[len - 1] - 'a' + 1], dp[i][ch[0] - 'a' + 1] + len);
    }
  }
  int ans = 0;
  for (int i = 1; i <= 26; i++) ans = max(ans, dp[i][i]);
  cout << ans;
  return 0;
}
