#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
int OO = 1e9;
const int N = 5e5 + 10, M = 128;
string str[N];
int dp[M][M];
int n, m, k, cnt, SU, idx, len, MN, MX, cur, T;
int l, r, mid;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL), cerr.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> str[i];
  for (char i = 'a'; i <= 'z'; ++i)
    for (char j = 'a'; j <= 'z'; ++j) dp[i][j] = -1e6;
  for (int i = 0; i < n; ++i) {
    char f = str[i].front();
    char s = str[i].back();
    for (char lvl = 'a'; lvl <= 'z'; ++lvl)
      dp[lvl][s] = max(dp[lvl][s], dp[lvl][f] + (int)(str[i].size()));
    dp[f][s] = max(dp[f][s], (int)(str[i].size()));
  }
  int ans = 0;
  for (char i = 'a'; i <= 'z'; ++i) ans = max(ans, dp[i][i]);
  cout << ans << "\n";
  return 0;
}
