#include <bits/stdc++.h>
using namespace std;
const int N = (int)5e5 + 10;
int dp[30][30];
int main() {
  int n;
  scanf("%d", &n);
  vector<string> vs(n + 1);
  for (int i = 1; i <= n; i++) cin >> vs[i];
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 26; j++) {
      if (j != vs[i].front() - 'a') {
        if (dp[j][vs[i].front() - 'a'] != 0) {
          dp[j][vs[i].back() - 'a'] =
              max(dp[j][vs[i].back() - 'a'],
                  dp[j][vs[i].front() - 'a'] + (int)vs[i].size());
        }
      } else {
        dp[j][vs[i].back() - 'a'] =
            max(dp[j][vs[i].back() - 'a'],
                dp[j][vs[i].front() - 'a'] + (int)vs[i].size());
      }
    }
  }
  int res = 0;
  for (int i = 0; i < 26; i++) res = max(res, dp[i][i]);
  printf("%d\n", res);
  return 0;
}
