#include <bits/stdc++.h>
using namespace std;
int n, m, dp[26][26];
string s;
int main() {
  while (cin >> n) {
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < n; i++) {
      cin >> s;
      m = s.size();
      for (int i = 0; i < 26; i++)
        if (dp[i][s[0] - 'a'])
          dp[i][s[m - 1] - 'a'] =
              max(dp[i][s[m - 1] - 'a'], dp[i][s[0] - 'a'] + m);
      dp[s[0] - 'a'][s[m - 1] - 'a'] = max(dp[s[0] - 'a'][s[m - 1] - 'a'], m);
    }
    int ans = 0;
    for (int i = 0; i < 26; i++) ans = max(ans, dp[i][i]);
    cout << ans << endl;
  }
  return 0;
}
