using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    static int[] lengths = new int[1 << (16 + 1)];
    static P()
    {
        for (int i = 0; i < lengths.Length; i++)
        {
            lengths[i] = Convert.ToString(i, 2).Length - 1;
        }
    }
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        string[] s = Enumerable.Repeat(0, n).Select(_ => Console.ReadLine()).ToArray();
        int[] encoded = s.Select(x => Convert.ToInt32("1" + x, 2)).ToArray();
        int[] cost = new int[1 << (16 + 1)];
        bool[] exists = new bool[1 << (16 + 1)];
        bool[] wasFirst = new bool[1 << (16 + 1)];
        List<int>[] descendance = Enumerable.Repeat(0, 1 << (16 + 1)).Select(_ => new List<int>()).ToArray();
        PriorityQueue<Tuple<int, int>, int> pqueue = new PriorityQueue<Tuple<int, int>, int>(x => x.Item2, false);
        for (int i = 0; i < n; i++)
        {
            pqueue.Push(new Tuple<int, int>(encoded[i], s[i].Length));
            exists[encoded[i]] = true;
            for (int j = 1; (encoded[i] >> j) != 1; j++)
            {
                descendance[encoded[i] >> j].Add(encoded[i]);
            }
        }
        while (pqueue.Count > 0)
        {
            var elem = pqueue.Pop();
            var code = elem.Item1;
            var length = elem.Item2;
            if (!wasFirst[code] && cost[code] != 0) continue;
            cost[code] = length;
            wasFirst[code] = length == lengths[code];
            if (code == 1) break;
            //        54321
            //code : 1xxxxx
            //
            for (int i = length == lengths[code] ? 1 : 0; (code >> i) != 1; i++)
            {
                if (exists[code >> i])
                {
                    pqueue.Push(new Tuple<int, int>((1 << i) | (code & ((1 << i) - 1)), length));
                }
            }

            foreach (var item in descendance[code])
            {
                var overLength = (lengths[item] - lengths[code]);
                pqueue.Push(new Tuple<int, int>((1 << overLength) | (item & ((1 << overLength) - 1)), length + overLength));
            }
        }
        Console.WriteLine(cost[1]);
    }
}

class PriorityQueue<TValue, TKey> where TKey : IComparable<TKey>
{
    public int Count { get; private set; }
    private Func<TValue, TKey> KeySelector;
    private bool Descendance;
    private TValue[] data = new TValue[65536];
    private TKey[] keys = new TKey[65536];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public PriorityQueue(Func<TValue, TKey> keySelector, bool descendance = false)
    { KeySelector = keySelector; Descendance = descendance; }
    public TValue Top
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get { ValidateNonEmpty(); return data[1]; }
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public TValue Pop()
    {
        var top = Top;
        var item = data[Count--];
        var key = KeySelector(item);
        int index = 1;
        while (true)
        {
            if ((index << 1) >= Count)
            {
                if (index << 1 > Count) break;
                if (key.CompareTo(keys[index << 1]) > 0 ^ Descendance)
                { data[index] = data[index << 1]; keys[index] = keys[index << 1]; index <<= 1; }
                else break;
            }
            else
            {
                var nextIndex = keys[index << 1].CompareTo(keys[(index << 1) + 1]) <= 0 ^ Descendance ? (index << 1) : (index << 1) + 1;
                if (key.CompareTo(keys[nextIndex]) > 0 ^ Descendance)
                { data[index] = data[nextIndex]; keys[index] = keys[nextIndex]; index = nextIndex; }
                else break;
            }
        }
        data[index] = item;
        keys[index] = key;
        return top;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Push(TValue item)
    {
        var key = KeySelector(item);
        int index = ++Count;
        if (data.Length == Count) Extend(data.Length * 2);
        while ((index >> 1) != 0)
        {
            if (keys[index >> 1].CompareTo(key) > 0 ^ Descendance)
            { data[index] = data[index >> 1]; keys[index] = keys[index >> 1]; index >>= 1; }
            else break;
        }
        data[index] = item;
        keys[index] = key;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    private void Extend(int newSize)
    {
        TValue[] newData = new TValue[newSize];
        TKey[] newKeys = new TKey[newSize];
        data.CopyTo(newData, 0);
        keys.CopyTo(newKeys, 0);
        data = newData;
    }
    private void ValidateNonEmpty() { if (Count == 0) throw new IndexOutOfRangeException(); }
}


Measured memory_bytes: 31240