#include <bits/stdc++.h>
const int dx[] = {0, -1, 0, 1, 1, 1, -1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int OO = 0x3f3f3f3f, N = 5000 + 5, mod = 1e9 + 7;
using namespace std;
void run() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int dp[26][26];
int main() {
  run();
  int n;
  cin >> n;
  memset(dp, -1, sizeof(dp));
  while (n--) {
    string s;
    cin >> s;
    int first = s[0] - 'a';
    int lst = s.back() - 'a';
    for (int i = 0; i < 26; ++i) {
      if (~dp[i][first])
        dp[i][lst] = max(dp[i][lst], dp[i][first] + (int)s.size());
    }
    dp[first][lst] = max(dp[first][lst], (int)s.size());
  }
  int ans = 0;
  for (int i = 0; i < 26; ++i) ans = max(ans, dp[i][i]);
  cout << ans << '\n';
}
