using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;

class Program
{
    struct pair
    {
        public int index;
        public int deff;
    }

    static pair GetNear(List<int> list, int value) { //Get index
        List<int> Deffes = new List<int>();
        for(int i = 0;i < list.Count; i++) {
            Deffes.Add(Math.Abs(list[i] - value));
        }
        return new pair() { index = Deffes.IndexOf(Deffes.Min()), deff = Deffes.Min() };
    }
    static pair GetUnder(List<int> list,int value) {
        pair Result = new pair() { index = -1, deff = 1000000000 } ;
        for(int ind = 0;ind < list.Count; ind++) {
            if (list[ind] >= value)
                continue;
            else if(Math.Abs(value - list[ind]) < Result.deff) {
                Result.index = ind;
                Result.deff = Math.Abs(value - list[ind]);
            }
        }
        return Result;
    }

    static void Main(string[] args) {
        var list = new List<string>(ReadLine().Split(' ')).Select(ele => Int32.Parse(ele)).ToList();
        var l = new List<int>();
        bool[] IsMatched = { false, false, false };
        for (int Count = 0; Count < list[0]; Count++)
            l.Add(Int32.Parse(ReadLine()));
        bool[] IsUsed = new bool[l.Count];
        for (int i = 0; i < IsUsed.Length; i++) IsUsed[i] = false;

        //すでに一致していたら。
        for(int Count = 1;Count < list.Count; Count++) {
            int index = l.IndexOf(list[Count]);
            if(index != -1) {
                l.RemoveAt(index);
                IsMatched[Count -1] = true;
            }
        }

        int MP = 0;

        //最小値より小さかったら。
        //⇒小さく短縮魔法したない。MP += Length
        int Min = l.Min();
        for(int Count = 1;Count < list.Count; Count++) {
            if (IsMatched[Count - 1] == true) continue;

            if(list[Count] < Min) {
                MP += list[Count] - Min;
                l.Remove(Min);
                Min = l.Min();
                IsMatched[Count - 1] = true;
            }
        }

        for(int Count = 1;Count < list.Count; Count++) {
            if (IsMatched[Count - 1] == true) continue;

            if(list[Count] > Min) { //一応
                pair p = GetNear(l, list[Count]);
                if(p.deff <= 10) {
                    MP += p.deff + 1;
                    IsMatched[Count - 1] = true;
                    l.RemoveAt(p.index);
                } else {

                    LABEL:

                    pair p_ = GetUnder(l, list[Count]);

                    List<int> Plused = new List<int>();
                    for(int i = 0;i < l.Count; i++) {
                        Plused.Add(l[i] + l[p_.index]);
                    }

                    MP += 10;
                    l.RemoveAt(p_.index);

                    pair AfterP = GetNear(Plused, list[Count]);
                    if(AfterP.deff > 10) {

                        goto LABEL;
                    } else {
                        MP += AfterP.deff;
                        l.RemoveAt(AfterP.index);
                        IsMatched[Count - 1] = true;
                    }
                }
            } else {
                WriteLine("メッセージは出ないはずだよ。");
            }
        }

        WriteLine(MP);

        ReadLine();
    }
}
