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