#include <bits/stdc++.h>
using namespace std;
const int maxint = -1u >> 2;
const double eps = 1e-6;
int main() {
  int n;
  cin >> n;
  string s = "";
  int dp[150][150];
  memset(dp, 0, sizeof(dp));
  while (n--) {
    cin >> s;
    int size = s.size();
    for (int i = 'a'; i <= 'z'; ++i) {
      if (dp[i][s[0]] != 0) {
        dp[i][s[size - 1]] = max(dp[i][s[size - 1]], dp[i][s[0]] + size);
      }
    }
    dp[s[0]][s[size - 1]] = max(dp[s[0]][s[size - 1]], size);
  }
  int maxLen = 0;
  for (int i = 'a'; i <= 'z'; ++i) {
    maxLen = max(maxLen, dp[i][i]);
  }
  cout << maxLen << endl;
  return 0;
}
