#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
int main() {
  int n;
  cin >> n;
  int arr[n][3];
  for (int i = 0; i < n; i++) {
    string temp;
    cin >> temp;
    arr[i][0] = temp[0] - 'a';
    arr[i][1] = temp[temp.size() - 1] - 'a';
    arr[i][2] = temp.size();
  }
  int dp[26][26];
  for (int i = 0; i < 26; i++)
    for (int j = 0; j < 26; j++) dp[i][j] = -1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      if (dp[j][arr[i][0]] != -1) {
        dp[j][arr[i][1]] = max(dp[j][arr[i][1]], arr[i][2] + dp[j][arr[i][0]]);
      }
    }
    dp[arr[i][0]][arr[i][1]] = max(dp[arr[i][0]][arr[i][1]], arr[i][2]);
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, dp[i][i]);
  cout << ans;
  return 0;
}
