using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
class Program
{   
    static IEnumerable<int[]> Pattern(int index, int n, int[] array)
    {
        if(index == n)
            yield return array;
        else
        {
            foreach(int i in Enumerable.Range(0, 4))
            {
                array[index] = i;
                foreach(var ret in Pattern(index + 1, n, array))
                    yield return ret;
            }
        }
    }
    public void Slove()
    {
        var inputs = Console.ReadLine().Split();
        int n = int.Parse(inputs[0]);
        int[] target = 
            inputs.Skip(1)
            .Select(int.Parse)
            .OrderBy(x => x)
            .ToArray();
        int[] bsum = new int[2 << n];
        int[] bamboo =
            Enumerable.Range(0, n)
            .Select(x => int.Parse(Console.ReadLine()))
            .ToArray();
        foreach(int i in Enumerable.Range(0, bsum.Length))
        {
            foreach(int j in Enumerable.Range(0, n))
            {
                if((i >> j & 1) == 1)
                    bsum[i] += bamboo[j];
            }
        }
      //System.Console.WriteLine(string.Join(",", bsum));
        long min =
            Pattern(0, n, new int[n])
            .Select(x => 
            {
                //System.Console.WriteLine(string.Join(",", x));
                int[] a = new int[]
                {
                    x.Reverse().Aggregate(0, (tsum, y) => (tsum << 1) + (y == 0 ? 1 : 0)),
                    x.Reverse().Aggregate(0, (tsum, y) => (tsum << 1) + (y == 1 ? 1 : 0)),
                    x.Reverse().Aggregate(0, (tsum, y) => (tsum << 1) + (y == 2 ? 1 : 0)),
                };
                return target.Select((y, index) => 
                    bsum
                    .Select((z, i) => i == 0 ? (long)int.MaxValue : Math.Abs(y - z) + (Convert.ToString(i, 2).Count(num => num == '1') - 1) * 10)
                    .Where((z, i) => (i | a[index]) == a[index])
                    .Min()
                )
                //.Select(z => {System.Console.WriteLine(z); return z;})
                .Sum();
            })
            .Min();
        System.Console.WriteLine(min);
    }
    
    static void Main(string[] args)
    {
        new Program().Slove();
    }
}
