#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n;
  char temp[15];
  int dp[26][26] = {0};
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> temp;
    int sized = strlen(temp);
    int start = temp[0] - 97;
    int end = temp[sized - 1] - 97;
    for (int i = 0; i < 26; ++i) {
      if (dp[i][start] != 0)
        dp[i][end] = max(dp[i][end], dp[i][start] + (int)sized);
    }
    dp[start][end] = max(dp[start][end], (int)sized);
  }
  int mans = -1;
  for (int i = 0; i < 26; ++i) {
    mans = max(mans, dp[i][i]);
  }
  cout << mans << endl;
  return 0;
}
