using System;

class quiz
{
    public int solve(int N, int[] L)
    {
        int[] Lprime = new int[N];
        int length;

        Lprime[0] = L[0];

        for (int i = 1; i < N; i++)
        {
            Lprime[i] = L[i] + Lprime[i - 1];
        }

        length = Lprime[N - 1];
        int[,] dp = new int[N + 1, length + 1];

        for (int i = 0; i < N + 1; i++)
        {
            for (int j = 0; j < length + 1; j++)
            {
                dp[i, j] = -1;
            }
        }

        for (int i = 0; i <= Lprime[0]; i++)
        {
            dp[1, i] = Lprime[0] - i;
        }

        for (int i = 1; i <= N; i++)
        {
            for (int j = 0; j <= Lprime[i - 1]; j++)
            {
                for (int k = 1; k < i; k++)
                {
                    if (dp[k, j] >= 0)
                    {
                        if (Lprime[i - 1] >= Lprime[k - 1] + j)
                        {
                            if (dp[i, j] >= 0)
                                dp[i, j] = Math.Min(dp[i, j], Math.Max(dp[k, j], Lprime[i - 1] - Lprime[k - 1] - j));
                            else
                                dp[i, j] = Math.Max(dp[k, j], Lprime[i - 1] - Lprime[k - 1] - j);
                        }
                        else if(i<N)
                        {
                            if (dp[i, j] >= 0)
                                dp[i, j] = Math.Min(dp[i, j], dp[k, j] + Lprime[i - 1] - Lprime[k - 1]);
                            else
                                dp[i, j] = dp[k, j] + Lprime[i - 1] - Lprime[k - 1];
                        }
                        //
                        //else必要？
                        //
                    }
                    else if(i < N)
                    {
                        dp[i, j] = Lprime[i - 1] - j;
                    }
                    //
                    //もしかしてここ？
                    //
                }
            }
        }

        int ans = int.MaxValue;

        for (int i = 0; i < length + 1; i++)
        {
            if (dp[N, i] >= 0)
                ans = Math.Min(ans, dp[N, i]);
        }

        return ans;
    }

    public int[] ParseIntBySpace(string str)
    {
        int[] array = new int[str.Length];
        int lastloc = 0, spaceloc = -1;

        for (int i = 0; i < str.Length; i++)
        {
            if (str[i] == ' ')
            {
                array[lastloc++] = int.Parse(str.Substring(spaceloc + 1, i - spaceloc - 1));
                spaceloc = i;
            }
            else if (i == str.Length - 1)
            {
                array[lastloc++] = int.Parse(str.Substring(spaceloc + 1, i - spaceloc));
            }
        }

        Array.Resize(ref array, lastloc);

        return array;
    }
}

class Example
{
    static void Main()
    {
        quiz ex = new quiz();
        int N;

        //while (true)
        //{
        N = int.Parse(Console.ReadLine());
        int[] L = new int[N];

        for (int i = 0; i < N; i++)
        {
            L[i] = int.Parse(Console.ReadLine());
        }
        //while (true)
        //{
        Console.WriteLine(ex.solve(N, L));
        //}
        //}
    }
}


Measured memory_bytes: 26636