#include <bits/stdc++.h>
using namespace std;
int dp[150][150];
int main() {
  int n;
  cin >> n;
  for (char a = 'a'; a <= 'z'; a++)
    for (char b = 'a'; b <= 'z'; b++) dp[a][b] = -2000000009;
  for (char c = 'a'; c <= 'z'; c++) dp[c][c] = 0;
  while (n--) {
    string s;
    cin >> s;
    char a = s[0], b = s[s.length() - 1];
    for (char c = 'a'; c <= 'z'; c++)
      dp[c][b] = max(dp[c][b], dp[c][a] + (int)s.length());
  }
  int ans = 0;
  for (char c = 'a'; c <= 'z'; c++) ans = max(ans, dp[c][c]);
  cout << ans << endl;
  return 0;
}
