#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007, INF = 2000000001;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1, 0},
    dy[] = {-1, 0, 1, 0, -1, 1, 1, -1, 0};
const double EPS = 1e-9;
void init(string fname) {
  freopen((fname + ".in").c_str(), "r", stdin);
  freopen((fname + ".out").c_str(), "w", stdout);
}
long long gcd(long long a, long long b) { return (b != 0) ? gcd(b, a % b) : a; }
long long modpow(long long a, long long x, long long m = mod) {
  int p = 1;
  while (x > 0) {
    if (x & 1 == 1) {
      p = p * a % m;
      --x;
    } else {
      x >>= 1;
      a = a * a % m;
    }
  }
  return p;
}
void getZ(const string& s, vector<int>& v) {
  v = vector<int>(s.length());
  int n = s.length();
  for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r) v[i] = min(v[i - l], r - i + 1);
    while (i + v[i] < n && s[v[i]] == s[i + v[i]]) ++v[i];
    if (i + v[i] - 1 > r) r = (l = i) + v[i] - 1;
  }
}
long long dfs(vector<vector<int> >& g, vector<long long>& a, int v,
              vector<bool>& used, vector<long long>& pop) {
  used[v] = true;
  long long ans = a[v];
  for (int i = 0; i < g[v].size(); ++i) {
    if (!used[g[v][i]]) {
      ans += dfs(g, a, g[v][i], used, pop);
    }
  }
  return pop[v] = ans;
}
void make_set(vector<int>& p, vector<int>& r, int v) {
  p[v] = v;
  r[v] = 0;
}
int find_set(vector<int>& p, int v) {
  return p[v] == v ? v : p[v] = find_set(p, p[v]);
}
void unite_sets(vector<int>& p, vector<int>& r, int v1, int v2) {
  int p1 = v1, p2 = v2;
  if (r[p1] > r[p2]) swap(p1, p2);
  p[p1] = p2;
  if (r[p1] == r[p2]) ++r[p2];
}
class Edge {
 public:
  double weight;
  int v1, v2;
  Edge(double w = 0, int i = 0, int j = 0) : weight(w), v1(i), v2(j) {}
};
class CompEdge {
 public:
  bool operator()(const Edge& a, const Edge& b) const {
    return (a.weight < b.weight) ||
           (a.weight == b.weight &&
            (a.v1 < b.v1 || (a.v1 == b.v1 && a.v2 < b.v2)));
  }
};
long long gcdex(long long a, long long b, long long& x, long long& y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  } else {
    long long x1, y1;
    long long g = gcdex(b % a, a, x1, y1);
    x = y1 - b / a * x1;
    y = x1;
    return g;
  }
}
void _a() {}
void _b() {}
void _c() {
  int n;
  cin >> n;
  vector<string> names(n);
  for (int i = 0; i < n; ++i) cin >> names[i];
  vector<vector<int> > dp(26, vector<int>(26));
  for (int i = 0; i < n; ++i) {
    char b = names[i][0], e = names[i][names[i].length() - 1];
    for (int j = 0; j < 26; ++j) {
      if (dp[j][b - 'a'] > 0) {
        dp[j][e - 'a'] =
            max(dp[j][b - 'a'] + (int)names[i].length(), dp[j][e - 'a']);
      }
    }
    dp[b - 'a'][e - 'a'] = max(dp[b - 'a'][e - 'a'], (int)names[i].length());
  }
  int ans = 0;
  for (int i = 0; i < 26; ++i) ans = max(ans, dp[i][i]);
  cout << ans;
}
void _d() {}
void _e() {}
int main() {
  _c();
  return 0;
}
