#include <bits/stdc++.h>
using namespace std;
template <class T>
void pp(T v) {
  for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
    cout << *it << ' ';
  cout << endl;
}
template <class T>
void pp(T v, int n) {
  for (int i = 0; i < (int)n; i++) cout << v[i] << ' ';
  cout << endl;
}
template <class T>
inline void chmax(T &a, const T b) {
  a = max(a, b);
}
template <class T>
inline void chmin(T &a, const T b) {
  a = min(a, b);
}
const int INF = 1 << 28;
const double EPS = 1.0e-9;
static const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int main(void) {
  int tbl[26][26];
  memset(tbl, 0, sizeof(tbl));
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string name;
    cin >> name;
    const int len = name.size();
    char a = name[0], b = name[len - 1];
    for (int c = 0; c < 26; c++) {
      if (tbl[c][a - 'a'] > 0) chmax(tbl[c][b - 'a'], tbl[c][a - 'a'] + len);
    }
    chmax(tbl[a - 'a'][b - 'a'], len);
  }
  int ans = 0;
  for (int i = 0; i < (int)26; i++) {
    chmax(ans, tbl[i][i]);
  }
  cout << ans << endl;
  return 0;
}
