import java.util.Scanner;

public class Main {

    private static final Scanner  SC = new Scanner(System.in);
    private static final int ELEMENTS = SC.nextInt();
    private static final int[]  VALUE = load(SC);
    private static int[] load(Scanner sc){
        int[] value = new int[ELEMENTS];
        for (int i = 0; i < ELEMENTS; i++) {
            value[i] = sc.nextInt();
        }
        return value;
    }

    public static void main(String[] args) {
        int sumOfAll = 0;
        for (int i: VALUE){
            sumOfAll += i;
        }

        int turningPoint = 0;
        int partialSum = 0;
        for (int i=0;i<VALUE.length;i++){
            partialSum += VALUE[i];
            sumOfAll -= VALUE[i];
            if(sumOfAll-partialSum<0){
                turningPoint = i;
                break;
            }
        }

        int resultA = partialSum-sumOfAll;
        int resultB = sumOfAll-partialSum+2*VALUE[turningPoint];

        System.out.println(Math.min(resultA,resultB));
    }
}


/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz