import java.util.Scanner;

/**
 * Created by kdonohue on 1/2/17.
 */
public class ChiefHopper {
    private final int[] buildings;

    public ChiefHopper(int size) {
        buildings = new int[size];
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        ChiefHopper hopper = new ChiefHopper(n);
        for (int i = 0; i < n; i++) {
            hopper.addBuilding(i, in.nextInt());
        }
        hopper.printFinalAnswer();
    }

    private void printFinalAnswer() {
        int max = findMax();
        int min = 0;
        while (min < max) {
            int guess = (int) Math.floor((min+max)/2.0);
            System.err.print(String.format("Guessing: %s, [%s, %s]: ", guess, min, max));
            if (canPassWith(guess)) {
                System.err.println(" SUCCESS");
                max = Math.min(max-1, guess);
            } else {
                System.err.println(" FAILURE");
                min = Math.max(min+1,guess);
            }
        }
        System.err.println("Max that worked: " + max);
        System.out.println(max);
    }

    private int findMax() {
        int guess = 1;
        while (!canPassWith(guess)) {
            guess *= 2;
        }
        return  guess;
    }

    private boolean canPassWith(int guess) {
        System.err.print(guess + ": ");
        for (int buildingHeight : buildings) {
            System.err.print(guess + ", ");
            if (guess < 0) {
                return false;
            }
            guess += guess - buildingHeight;
        }
        System.err.println( "FINAL: " + guess);
        return guess > 0;
    }

    private void addBuilding(int i, int nextInt) {
        buildings[i] = nextInt;
    }
}

@@ -1,8 +1,33 @@
+import java.util.Arrays;%0A
 import j
@@ -130,14 +130,8 @@
 ate 
-final 
 int%5B
@@ -479,32 +479,66 @@
 t());%0A        %7D%0A
+        hopper.finishBuildings();%0A
         hopper.p
@@ -555,32 +555,747 @@
 nswer();%0A    %7D%0A%0A
+    private void finishBuildings() %7B%0A        /*%0A        System.err.println(%22Initial array: %22 + Arrays.toString(buildings));%0A        int maxLoc = 0;%0A        int max = Arrays.stream(buildings).max().getAsInt();%0A        System.err.println(%22max val %22 + max);%0A        for (int i = 0; i %3C buildings.length; i++) %7B%0A           if (max == buildings%5Bi%5D) %7B%0A               maxLoc = i + 1;%0A               System.err.println(%22max loc %22 + maxLoc);%0A               break;%0A           %7D%0A        %7D%0A        int%5B%5D newBuildings = new int%5BmaxLoc%5D;%0A        System.arraycopy(buildings, 0, newBuildings, 0, maxLoc);%0A        buildings = newBuildings;%0A        System.err.println(%22Final array: %22 + Arrays.toString(buildings));%0A        */%0A    %7D%0A%0A
     private void
@@ -2091,19 +2091,20 @@
 assWith(
-int
+long
  guess) 
@@ -2139,18 +2139,17 @@
 uess + %22
-: 
+%7B
 %22);%0A    
@@ -2156,119 +2156,192 @@
     
-for (int buildingHeight : buildings) %7B%0A            System.err.print(guess + %22, %22);%0A            if (guess %3C 0) %7B
+int theMax = Arrays.stream(buildings).max().getAsInt();%0A        for (int buildingHeight : buildings) %7B%0A            if (guess %3E theMax) %7B%0A                System.err.println(%22CLEARED%7D%22);
 %0A   
@@ -2364,12 +2364,11 @@
 urn 
-fals
+tru
 e;%0A 
@@ -2425,16 +2425,180 @@
 Height;%0A
+            System.err.print(guess + %22-%3E%22);%0A            if (guess %3C 0) %7B%0A                System.err.println(%22FAILED%7D%22);%0A                return false;%0A            %7D%0A
         
@@ -2640,24 +2640,30 @@
 L: %22 + guess
+ + %22%7D%22
 );%0A        r
@@ -2675,16 +2675,17 @@
  guess %3E
+=
  0;%0A    

Make Chief Hopper work