#include <bits/stdc++.h>
using namespace std;
int n, dp[28][28], answer;
string s;
int main() {
  scanf("%d", &n);
  for (int i = 0; i <= 'z' - 'a'; i++)
    for (int j = 0; j <= 'z' - 'a'; j++) dp[i][j] = -2e9;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    for (int j = 0; j <= 'z' - 'a'; j++)
      dp[j][s[s.size() - 1] - 'a'] =
          max(dp[j][s[s.size() - 1] - 'a'], dp[j][s[0] - 'a'] + (int)s.size());
    dp[s[0] - 'a'][s[s.size() - 1] - 'a'] =
        max(dp[s[0] - 'a'][s[s.size() - 1] - 'a'], int(s.size()));
  };
  for (int i = 0; i <= 'z' - 'a'; i++) answer = max(answer, dp[i][i]);
  printf("%d\n", answer);
  return 0;
}
