import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> o = new ArrayList<>();
        for(int i = 0;i < n;i++){
            o.add(sc.nextInt());
        }
        long min = Integer.MAX_VALUE;
        for(int i = 0;i < n;i++){
            List<Integer> g1 = new ArrayList<>();
            List<Integer> g2 = new ArrayList<>();
            long r1 = 0;
            long r2 = 0;
            for(int j = 0;j < i;j++){
                g1.add(o.get(j));
            }
            for(int j = i;j < n;j++){
                g2.add(o.get(j));
            }
            for(int one : g1){
                r1 += one;
            }
            for(int two : g2){
                r2 += two;
            }
            long r = r1 - r2;
            if(r < 0){
                r *= -1;
            }
            if(min > r){
                min = r;
            }
        }
        System.out.println(min);
    }
}
/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