#include <bits/stdc++.h>
using namespace std;
template <class T>
void chmin(T &t, const T &f) {
  if (t > f) t = f;
}
template <class T>
void chmax(T &t, const T &f) {
  if (t < f) t = f;
}
int mod = 1e9 + 7;
double pi = 3.1415926535897932384;
int main() {
  int dp[30][30];
  for (int i = 0; i < 30; ++i) {
    for (int j = 0; j < 30; ++j) dp[i][j] = -1;
  }
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    char a[15];
    scanf("%s", a);
    int len = strlen(a);
    for (int i = 0; i < 30; ++i) {
      if (dp[i][a[0] - 'a'] != -1)
        dp[i][a[len - 1] - 'a'] =
            max(dp[i][a[len - 1] - 'a'], len + dp[i][a[0] - 'a']);
    }
    dp[a[0] - 'a'][a[len - 1] - 'a'] =
        max(len, dp[a[0] - 'a'][a[len - 1] - 'a']);
  }
  int ans = 0;
  for (char i = 'a'; i <= 'z'; ++i) {
    ans = max(ans, dp[i - 'a'][i - 'a']);
  }
  printf("%d\n", ans);
  return 0;
}
