#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
const long long int inf = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
const double PI = acos(-1);
long long int i, j, k;
void solve(void);
inline bool equal(double a, double b) { return fabs(a - b) < eps; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  int t = 1;
  while (t--) solve();
  return 0;
}
void solve() {
  int n;
  cin >> n;
  string s[n + 1];
  for (i = (1); i <= (n); ++i) cin >> s[i];
  long long int dp[26][26];
  for (i = (0); i <= (25); ++i)
    for (j = (0); j <= (25); ++j) dp[i][j] = -mod;
  for (i = (0); i <= (25); ++i) dp[i][i] = 0;
  for (i = (0); i <= (25); ++i)
    for (j = (1); j <= (n); ++j) {
      int st = s[j][0] - 'a', en = s[j][(long long)s[j].size() - 1] - 'a';
      dp[i][en] = ((dp[i][en]) > (dp[i][st] + (long long)s[j].size())
                       ? (dp[i][en])
                       : (dp[i][st] + (long long)s[j].size()));
    }
  long long int maxx = 0;
  for (i = (0); i <= (25); ++i)
    maxx = ((maxx) > (dp[i][i]) ? (maxx) : (dp[i][i]));
  cout << maxx << '\n';
}
