#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:256000000")
template <class T>
inline T sqr(T a) {
  return a * a;
}
void pr(int dp[200][200]) {
  puts("--------------------------------------");
  for (int i = 'a'; i <= 'z'; ++i) {
    for (int j = 'a'; j <= 'z'; ++j) {
      printf("%d ", dp[i][j]);
    }
    puts("");
  }
}
int main() {
  int n;
  scanf("%d", &n);
  int dp[200][200] = {0};
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    int l = s.length();
    for (int x = 'a'; x <= 'z'; ++x)
      if (dp[x][s[0]]) dp[x][s[l - 1]] = max(dp[x][s[l - 1]], l + dp[x][s[0]]);
    dp[s[0]][s[l - 1]] = max(dp[s[0]][s[l - 1]], l);
  }
  int res = 0;
  for (int i = 'a'; i <= 'z'; ++i) res = max(res, dp[i][i]);
  cout << res;
  return 0;
}
