
// problem: "https://atcoder.jp/contests/abc129/tasks"

import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.lang.Math;

class Main {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int i;
        ArrayList<Integer> V = new ArrayList<>();
        for(i=0;i!=n;i++)
            V.add(in.nextInt());

        int s1,s2;
        s1 = s2 = 0;
        for(i=0;i!=n;i++)
            s2 += V.get(i);
        int m = s2;
        for(i=0;i!=n;i++) {
            m = Math.min(m,Math.abs(s2-s1));
            s1 += V.get(i);
            s2 -= V.get(i);
        }

        m = Math.min(m,Math.abs(s2-s1));

        System.out.print(m);
    }
} import java.util.Scanner; Scanner java.util import java.util.List; List java.util import java.util.ArrayList; ArrayList java.util import java.lang.Math; Math java.lang class Main {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int i;
        ArrayList<Integer> V = new ArrayList<>();
        for(i=0;i!=n;i++)
            V.add(in.nextInt());

        int s1,s2;
        s1 = s2 = 0;
        for(i=0;i!=n;i++)
            s2 += V.get(i);
        int m = s2;
        for(i=0;i!=n;i++) {
            m = Math.min(m,Math.abs(s2-s1));
            s1 += V.get(i);
            s2 -= V.get(i);
        }

        m = Math.min(m,Math.abs(s2-s1));

        System.out.print(m);
    }
} Main public static void main(String args[]) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int i;
        ArrayList<Integer> V = new ArrayList<>();
        for(i=0;i!=n;i++)
            V.add(in.nextInt());

        int s1,s2;
        s1 = s2 = 0;
        for(i=0;i!=n;i++)
            s2 += V.get(i);
        int m = s2;
        for(i=0;i!=n;i++) {
            m = Math.min(m,Math.abs(s2-s1));
            s1 += V.get(i);
            s2 -= V.get(i);
        }

        m = Math.min(m,Math.abs(s2-s1));

        System.out.print(m);
    } main {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int i;
        ArrayList<Integer> V = new ArrayList<>();
        for(i=0;i!=n;i++)
            V.add(in.nextInt());

        int s1,s2;
        s1 = s2 = 0;
        for(i=0;i!=n;i++)
            s2 += V.get(i);
        int m = s2;
        for(i=0;i!=n;i++) {
            m = Math.min(m,Math.abs(s2-s1));
            s1 += V.get(i);
            s2 -= V.get(i);
        }

        m = Math.min(m,Math.abs(s2-s1));

        System.out.print(m);
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int i; i ArrayList<Integer> V = new ArrayList<>(); V new ArrayList<>() for(i=0;i!=n;i++)
            V.add(in.nextInt()); i=0; i=0 i 0 i!=n i n i++ i++ i V.add(in.nextInt()); V.add(in.nextInt()) V.add V in.nextInt() in.nextInt in int s1 s1 s2; s2 s1 = s2 = 0 s1 s2 = 0 s2 0 for(i=0;i!=n;i++)
            s2 += V.get(i); i=0; i=0 i 0 i!=n i n i++ i++ i s2 += V.get(i); s2 += V.get(i) s2 V.get(i) V.get V i int m = s2; m s2 for(i=0;i!=n;i++) {
            m = Math.min(m,Math.abs(s2-s1));
            s1 += V.get(i);
            s2 -= V.get(i);
        } i=0; i=0 i 0 i!=n i n i++ i++ i {
            m = Math.min(m,Math.abs(s2-s1));
            s1 += V.get(i);
            s2 -= V.get(i);
        } {
            m = Math.min(m,Math.abs(s2-s1));
            s1 += V.get(i);
            s2 -= V.get(i);
        } m = Math.min(m,Math.abs(s2-s1)) m Math.min(m,Math.abs(s2-s1)) Math.min Math m Math.abs(s2-s1) Math.abs Math s2-s1 s2 s1 s1 += V.get(i) s1 V.get(i) V.get V i s2 -= V.get(i) s2 V.get(i) V.get V i m = Math.min(m,Math.abs(s2-s1)) m Math.min(m,Math.abs(s2-s1)) Math.min Math m Math.abs(s2-s1) Math.abs Math s2-s1 s2 s1 System.out.print(m) System.out.print System.out System System.out m String args[] args

// problem: "https://atcoder.jp/contests/abc129/tasks"

import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.lang.Math;

class Main {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int i;
        ArrayList<Integer> V = new ArrayList<>();
        for(i=0;i!=n;i++)
            V.add(in.nextInt());

        int s1,s2;
        s1 = s2 = 0;
        for(i=0;i!=n;i++)
            s2 += V.get(i);
        int m = s2;
        for(i=0;i!=n;i++) {
            m = Math.min(m,Math.abs(s2-s1));
            s1 += V.get(i);
            s2 -= V.get(i);
        }

        m = Math.min(m,Math.abs(s2-s1));

        System.out.print(m);
    }
}
