#include <bits/stdc++.h>
using namespace std;
int t[30][30];
string s;
int main() {
  int N, ans;
  while (cin >> N) {
    memset(t, 0, sizeof t);
    for (int i = 1; i <= N; i++) {
      cin >> s;
      int len = s.size();
      int x = s[0] - 'a';
      int y = s[len - 1] - 'a';
      for (int i = 0; i < 26; i++) {
        for (int j = 0; j < 26; j++)
          if (j == x && t[i][j] != 0) t[i][y] = max(t[i][y], t[i][j] + len);
      }
      t[x][y] = max(t[x][y], len);
    }
    ans = 0;
    for (int i = 0; i < 26; i++) ans = max(ans, t[i][i]);
    cout << ans << endl;
  }
  return 0;
}
