#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
mt19937_64 randGen(system_clock().now().time_since_epoch().count());
mt19937 rnd(42);
const int N = 5e5 + 1;
const int E = 31;
struct Solver {
  int n, ln[N];
  int tb[N][2];
  void read() {
    string second;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> second;
      ln[i] = second.length();
      tb[i][0] = second[0] - 'a';
      tb[i][1] = second[ln[i] - 1] - 'a';
    }
  }
  void solve() {
    int ans = 0;
    int b[E][E] = {};
    int p[E][E] = {};
    int e[E] = {};
    for (int i = 0; i < n; i++) {
      int x = tb[i][0];
      int y = tb[i][1];
      int vle = max(b[y][x], p[y][x]);
      int pt[E] = {};
      for (int j = 0; j < E; j++) {
        if (p[j][x] > 0) {
          pt[j] = p[j][x] + ln[i];
        } else {
          pt[x] = max(pt[x], ln[i]);
        }
      }
      for (int j = 0; j < E; j++) {
        p[j][y] = max(p[j][y], pt[j]);
      }
      if (vle > 0) {
        e[y] = max(e[y], vle + ln[i]);
      }
      b[x][y] = max(b[x][y], ln[i]);
    }
    for (int i = 0; i < E; i++) {
      ans = max(ans, b[i][i]);
    }
    cout << max(ans, *max_element(e, e + E));
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  Solver sol;
  sol.read();
  sol.solve();
  return 0;
}
