#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
#ifndef _DEBUG
#define _DEBUG 0
#endif // !_DEBUG
#define IFD if (_DEBUG)
typedef long long ll, i64;
const int N = 2e5 + 50;
struct inp
{
    int st, ed, len;
} a[N];
char buf[20];
vector<int> stw[26], edw[26];
int dis[N];
bool inq[N];
int ideg[N], ideg_copy[N];
vector<int>::const_iterator hd[N];
int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%s", buf);
        a[i].len = strlen(buf);
        a[i].st = buf[0] - 'a';
        a[i].ed = buf[a[i].len - 1] - 'a';
        stw[a[i].st].push_back(i);
        edw[a[i].ed].push_back(i);
    }
    for (int i = 0; i < n; i++)
    {
        const auto &x = edw[a[i].st];
        const auto &y = stw[a[i].ed];
        ideg_copy[i] = lower_bound(x.begin(), x.end(), i) - x.begin();
        hd[i] = upper_bound(y.begin(), y.end(), i);
    }
    int ans = 0;
    for (int endp = 0; endp < 26; endp++)
    {
        queue<int> Q;
        for (int i = 0; i < n; i++)
            if ((ideg[i] = ideg_copy[i]) == 0 && a[i].st == endp) Q.push(i);
        memset(dis, 0, sizeof dis);
        while (!Q.empty())
        {
            int f = Q.front();
            Q.pop();
            if (a[f].ed == endp)
                ans = max(ans, dis[f] + a[f].len);
            for (auto it = hd[f]; it != stw[a[f].ed].end(); it++)
            {
                ideg[*it]--;
                dis[*it] = max(dis[*it], dis[f] + a[f].len);
                if (ideg[*it] == 0)
                    Q.push(*it);
            }
        }
    }
    if (0)
        for (int endp = 0; endp < 26; endp++)
        {
            memset(dis, 0, sizeof dis);
            queue<int> Q;
            for (auto x : stw[endp]) Q.push(x), inq[x] = true;
            while (!Q.empty())
            {
                int f = Q.front();
                Q.pop();
                inq[f] = false;
                if (a[f].ed == endp) ans = max(ans, dis[f] + a[f].len);
                for (auto it = upper_bound(stw[a[f].ed].begin(), stw[a[f].ed].end(), f);
                     it != stw[a[f].ed].end(); it++)
                    if (dis[*it] < dis[f] + a[f].len)
                    {
                        dis[*it] = dis[f] + a[f].len;
                        if (!inq[*it]) Q.push(*it), inq[*it] = true;
                    }
            }
        }
    cout << ans;
    return 0;
}