#include <bits/stdc++.h>
using namespace std;
int ans, le, fir, las;
int n, dp[30][30];
string str;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> str;
    le = str.length();
    fir = str[0] - 'a' + 1;
    las = str[str.length() - 1] - 'a' + 1;
    for (int j = 1; j <= 26; j++) {
      if (dp[j][fir] != 0) dp[j][las] = max(dp[j][fir] + le, dp[j][las]);
    }
    dp[fir][las] = max(le, dp[fir][las]);
  }
  for (int i = 1; i <= 26; i++) {
    ans = max(ans, dp[i][i]);
  }
  cout << ans << endl;
  cin.get();
  cin.get();
  return 0;
}
