#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  int T = 1;
  while (T--) {
    int n;
    cin >> n;
    int dp[1000][1000];
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < n; i++) {
      string second;
      cin >> second;
      for (int j = 0; j < 26; j++) {
        int l = second[0] - 'a';
        int r = second[second.size() - 1] - 'a';
        int x = second.size();
        if (dp[j][l] || l == j) {
          dp[j][r] = max(dp[j][r], dp[j][l] + x);
        }
      }
    }
    int ans = 0;
    for (int i = 0; i < 236; i++) {
      ans = max(ans, dp[i][i]);
    }
    cout << ans;
  }
  return 0;
}
