#include <bits/stdc++.h>
int diru[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dirv[] = {-1, 0, 1, -1, 1, -1, 0, 1};
using namespace std;
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
template <class T>
T sq(T n) {
  return n * n;
}
template <class T>
T gcd(T a, T b) {
  return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
  return (a / gcd<T>(a, b) * b);
}
template <class T>
bool inside(T a, T b, T c) {
  return a <= b && b <= c;
}
template <class T>
void setmax(T& a, T b) {
  if (a < b) a = b;
}
template <class T>
void setmin(T& a, T b) {
  if (b < a) a = b;
}
template <class T>
T power(T N, T P) {
  return (P == 0) ? 1 : N * power(N, P - 1);
}
int dp[500010];
bool isV[500010];
int pre[500010][26];
int len[500010];
int f[500010];
int s[500010];
char tmp[100];
int tar;
int cal(int i) {
  if (i < 0) return -(1 << 29);
  if (isV[i]) return dp[i];
  int ret;
  ret = max(len[i] + cal(pre[i + 1][s[i]]), cal(pre[i + 1][f[i]]));
  if (s[i] == tar) ret = max(ret, len[i]);
  isV[i] = 1;
  return dp[i] = ret;
}
int main() {
  int n, T, t = 1, m, i, j, k;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s", tmp);
    len[i] = strlen(tmp);
    f[i] = tmp[0] - 'a';
    s[i] = tmp[len[i] - 1] - 'a';
  }
  memset(pre, -1, sizeof(pre));
  for (i = n - 1; i > -1; i--) {
    for (j = 0; j < 26; j++) {
      if (j == f[i])
        pre[i][j] = i;
      else
        pre[i][j] = pre[i + 1][j];
    }
  }
  int ans = 0;
  for (i = 0; i < 26; i++) {
    tar = i;
    memset(isV, 0, sizeof(isV));
    ans = max(ans, cal(pre[0][i]));
  }
  printf("%d\n", ans);
  return 0;
}
