#include <bits/stdc++.h>
using namespace std;
int dp[30][30];
char buf[20];
int main(void) {
  int N, i, j;
  string s;
  cin >> N;
  for ((i) = 0; (i) < (int)(N); (i)++) {
    scanf("%s", buf);
    string s = buf;
    int len = s.length();
    int x = s[0] - 'a', y = s[len - 1] - 'a';
    for ((j) = 0; (j) < (int)(26); (j)++)
      if (dp[j][x] > 0) dp[j][y] = max(dp[j][y], dp[j][x] + len);
    dp[x][y] = max(dp[x][y], len);
  }
  int ans = 0;
  for ((i) = 0; (i) < (int)(26); (i)++) ans = max(ans, dp[i][i]);
  cout << ans << endl;
  return 0;
}
