10
abdcced
bdacdac
ecb
dc
eaeeebdd
adcdbadcac
eb
aadecccde
edbaeacad
accd
 100
d
a
e
eb
c
d
d
e
c
e
ac
d
c
aa
a
e
da
e
e
c
e
a
c
c
bc
bd
d
da
cc
be
b
a
ee
d
be
be
e
b
a
ed
cb
ab
a
ea
ac
aa
ed
d
b
eb
e
ed
c
ce
c
d
c
d
d
ee
e
b
ea
ea
da
ab
ba
ed
da
ec
ea
bd
ee
dc
d
bd
d
c
cc
ab
bd
a
ad
e
d
e
bc
bb
c
bc
a
a
e
ca
ac
c
ad
c
be
d
 3
ab
acb
ba
 10
a
b
a
c
b
a
b
a
a
a
 5
cab
bbc
caa
ccc
aca
 3
ac
abc
ca
 5
ab
bc
cd
de
ffffffffff
 16
ddgcb
fgbhgbdg
gha
dh
ddfb
fggbc
edb
hd
d
hfgcabf
hdaef
fhbcdgba
chee
cafeggc
f
ecb
 50
agecd
cghafi
fiide
iecc
jbdcfjhgd
diee
hfeg
ehc
gfijgjh
gacaifebg
dicbbddc
hjgciaei
jjcdh
g
gc
cf
hfdjhd
c
icidbec
ji
eeh
cgeejggc
acfd
jjg
ajefdj
eghhebiic
bih
gbb
jjaa
idc
gafi
ecg
dbigbjiehj
cedif
ahidfaaajg
hfhhiccbgb
dgegjgieif
hgjebhfdc
j
ahehd
ahdah
bijbhh
a
dabiggfhac
dedigbjbf
ihbdj
iihagchd
gfebhfdi
jbjdcggdh
f

0
 35
 5
 6
 9
 5
 10
 7
 37

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.List;

public class Main {
    public static void main(String[] args) throws IOException {
        InputStream stdin = System.in;
        OutputStream stdout = System.out;

        /*
         * InputStream fileIn = new FileInputStream(new File("input.txt"));
         * OutputStream fileOut = new FileOutputStream(new File("output.txt"));
         */

        InputReader in = new InputReader(stdin);
        OutputWriter out = new OutputWriter(stdout);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }
}

class Task {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.readInt();
        int dp[] = new int[5 * 100000];
        char[]left = new char[5 * 100000];
        char[]right = new char[5 * 100000];
        int[]len = new int[5 * 100000];
        int[]max = new int[5 * 100000];
        for (int i = 0; i < n; i++) {
            String s = in.readString();
            left[i] = s.charAt(0);
            right[i] = s.charAt(s.length() - 1);
            len[i] = s.length();
        }
        int res = 0;
        for (int i = 0; i < 26; i++) {
            for (int j = 0; j < 26; j++) {
                if (i == j) {
                    max[j] = 0;
                }
                else {
                    max[j] = Integer.MIN_VALUE;
                }
            }
            for (int j = 0; j < n; j++) {
                dp[j] = max[left[j] - 'a'] + len[j];
                max[right[j] - 'a'] = Math.max(max[right[j] - 'a'], dp[j]);
                if (right[j] - 'a' == i) {
                    res = Math.max(res, dp[j]);
                }
            }
        }
        out.printLine(res);
    }
}


class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public long readLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }
    
    public char readCharacter() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        return (char) c;
    }

    public static boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(outputStream);
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }
}

class StringUtil {
    public static int[] prefixFunction(String s) {
        int n = s.length();
        int[] p = new int[n];
        for (int i = 1; i < n; i++) {
            int k = p[i - 1];
            while (k > 0 && s.charAt(k) != s.charAt(i)) {
                k = p[k - 1];
            }
            p[i] = k + (s.charAt(k) == s.charAt(i) ? 1 : 0);
        }
        return p;
    }

    public static int kmpMatcher(String s, String pattern) {
        int m = pattern.length();
        if (m == 0) {
            return 0;
        }
        int n = s.length();
        int[] p = prefixFunction(pattern);
        int k = 0;
        for (int i = 0; i < n; i++) {
            while (k > 0 && s.charAt(i) != pattern.charAt(k)) {
                k = p[k - 1];
            }
            if (s.charAt(i) == pattern.charAt(k)) {
                k++;
            }
            if (k == m) {
                return i - m + 1;
            }
        }
        return -1;
    }
}

class CombinatoricaUtils {
    public static long getA(long k, long n) {
        return getP(n) / getP(n - k);
    }
    
    public static long getC(long k, long n) {
        BigInteger value = BigInteger.ONE;
        for (long i = 1; i <= n; i++) {
            value = value.multiply(new BigInteger(i + ""));
        }
        for (long i = 1; i <= k; i++) {
            value = value.divide(new BigInteger(i + "")); 
        }
        for (long i = 1; i <= n - k; i++) {
            value = value.divide(new BigInteger(i + ""));
        }
        return value.longValue();
    }
    
    public static long getP(long n) {
        long p = 1;
        while(n > 0) {
            p = (p * n);
            n--;
        }
        return p;
    }
}