#include <bits/stdc++.h>
using namespace std;
int dp[30][30];
char s[100];
int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < 26; i++) dp[i][i] = 0;
    for (int i = 0; i < n; i++) {
      scanf("%s", s);
      int len = strlen(s);
      for (int j = 0; j < 26; j++)
        if (dp[j][s[0] - 'a'] != -1) {
          if (dp[j][s[len - 1] - 'a'] == -1 ||
              dp[j][s[len - 1] - 'a'] < dp[j][s[0] - 'a'] + len)
            dp[j][s[len - 1] - 'a'] = dp[j][s[0] - 'a'] + len;
        }
    }
    int maxx = 0;
    for (int i = 0; i < 26; i++) maxx = max(dp[i][i], maxx);
    printf("%d\n", maxx);
  }
  return 0;
}
