#include <bits/stdc++.h>
using namespace std;
const int oo = (int)1e9;
const double PI = 2 * acos(0.0);
const double eps = 1e-9;
int n;
string names[500005];
int dp[26][26];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> names[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      if (dp[j][names[i][0] - 'a'] != 0)
        dp[j][names[i][names[i].size() - 1] - 'a'] =
            max(dp[j][names[i][names[i].size() - 1] - 'a'],
                (int)(dp[j][names[i][0] - 'a'] + names[i].length()));
    }
    dp[names[i][0] - 'a'][names[i][names[i].size() - 1] - 'a'] =
        max(dp[names[i][0] - 'a'][names[i][names[i].size() - 1] - 'a'],
            (int)names[i].size());
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, dp[i][i]);
  cout << ans << endl;
  return 0;
}
