#include <bits/stdc++.h>
using namespace std;
const int maxn = 500 * 1000 + 10, maxm = 26;
int n, x, y, dp[maxm][maxm], mx;
string s;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    x = s[0] - 'a';
    y = s[s.length() - 1] - 'a';
    for (int j = 0; j < 26; j++) {
      if (dp[j][x] > 0) dp[j][y] = max(dp[j][y], (int)s.length() + dp[j][x]);
      if (j == x) dp[j][y] = max(dp[j][y], (int)s.length());
    }
  }
  for (int i = 0; i < 26; i++) mx = max(mx, dp[i][i]);
  cout << mx;
  return 0;
}
