#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (((a) / gcd(a, b))) * b; }
int phi(int n) {
  int result = n;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      while (n % i == 0) n /= i;
      result -= result / i;
    }
  }
  if (n > 1) result -= result / n;
  return result;
}
long long power(long long a, long long b, long long c) {
  long long r = 1;
  while (b) {
    if (b & 1) r *= a;
    a *= a;
    a %= c;
    r %= c;
    b /= 2;
  }
  return r;
}
void nxi(int& n) {
  bool min = 0;
  char c;
  n = 0;
  while ((c = getc(stdin)) && c <= 32)
    ;
  if (c == '-')
    min = 1;
  else
    n = c - 48;
  while ((c = getc(stdin)) && c > 32) n = (n << 3) + (n << 1) + c - 48;
  if (min) n = -n;
}
void prl(int n) {
  if (n == 0) {
    puts("0");
    return;
  }
  static int s[10];
  int top = 0;
  while (n > 0) s[top++] = n % 10, n /= 10;
  while (top--) putchar(s[top] + 48);
  puts("");
}
using namespace std;
int n, a[100010];
int dp[500][500];
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    int k = s.length();
    int c1 = s[0] - 'a', c2 = s[k - 1] - 'a';
    for (int j = 0; j < 26; j++)
      if (dp[j][c1]) dp[j][c2] = max(dp[j][c2], dp[j][c1] + k);
    dp[c1][c2] = max(dp[c1][c2], k);
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, dp[i][i]);
  cout << ans << endl;
  return 0;
}
