#include <bits/stdc++.h>
using namespace std;
int dp[30][30], n, ans;
string c;
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> c;
    int len = c.length(), l = c[0] - 'a' + 1, r = c[len - 1] - 'a' + 1;
    for (int j = 1; j <= 26; ++j)
      if (dp[j][l]) dp[j][r] = max(dp[j][r], dp[j][l] + len);
    dp[l][r] = max(dp[l][r], len);
  }
  for (int i = 1; i <= 26; ++i) ans = max(ans, dp[i][i]);
  cout << ans;
}
