#include <bits/stdc++.h>
using namespace std;
int n;
string s[500001];
char line[10];
int dp[30][30];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    memset(line, 0, sizeof(line));
    scanf("%s", line);
    s[i] = line;
  }
  memset(dp, 0, sizeof(dp));
  for (int k = 0; k < n; ++k) {
    int len = (int)s[k].size();
    int start = s[k][0] - 'a', end = s[k][len - 1] - 'a';
    for (int i = 0; i < 26; ++i)
      if (dp[i][start]) {
        dp[i][end] = max(dp[i][end], dp[i][start] + len);
      }
    dp[start][end] = max(dp[start][end], len);
  }
  int ret = 0;
  for (int i = 0; i < 26; ++i) ret = max(ret, dp[i][i]);
  cout << ret << endl;
  return 0;
}
