import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        int[] ary = new int[n];
        for(int i = 0; i < n; i++)
        ary[i] = Integer.parseInt(line1[i]);
        int min = 4950;
        for(int i = 0; i < n; i++){
            int a = 0;
            int b = 0;
            for(int j = 0; j <= i; j++)
            a += ary[j];
            for(int k = i + 1; k < n; k++)
            b += ary[k];
            int c = a - b;
            if(c < 0)
            c = b - a;
            if(c < min)
            min = c;
        }
        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 = Integer.parseInt(sc.nextLine());
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        int[] ary = new int[n];
        for(int i = 0; i < n; i++)
        ary[i] = Integer.parseInt(line1[i]);
        int min = 4950;
        for(int i = 0; i < n; i++){
            int a = 0;
            int b = 0;
            for(int j = 0; j <= i; j++)
            a += ary[j];
            for(int k = i + 1; k < n; k++)
            b += ary[k];
            int c = a - b;
            if(c < 0)
            c = b - a;
            if(c < min)
            min = c;
        }
        System.out.println(min);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        int[] ary = new int[n];
        for(int i = 0; i < n; i++)
        ary[i] = Integer.parseInt(line1[i]);
        int min = 4950;
        for(int i = 0; i < n; i++){
            int a = 0;
            int b = 0;
            for(int j = 0; j <= i; j++)
            a += ary[j];
            for(int k = i + 1; k < n; k++)
            b += ary[k];
            int c = a - b;
            if(c < 0)
            c = b - a;
            if(c < min)
            min = c;
        }
        System.out.println(min);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        int[] ary = new int[n];
        for(int i = 0; i < n; i++)
        ary[i] = Integer.parseInt(line1[i]);
        int min = 4950;
        for(int i = 0; i < n; i++){
            int a = 0;
            int b = 0;
            for(int j = 0; j <= i; j++)
            a += ary[j];
            for(int k = i + 1; k < n; k++)
            b += ary[k];
            int c = a - b;
            if(c < 0)
            c = b - a;
            if(c < min)
            min = c;
        }
        System.out.println(min);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.nextLine()); n Integer.parseInt(sc.nextLine()) Integer.parseInt Integer sc.nextLine() sc.nextLine sc String line = sc.nextLine(); line sc.nextLine() sc.nextLine sc String[] line1 = line.split(" "); line1 line.split(" ") line.split line " " int[] ary = new int[n]; ary new int[n] n for(int i = 0; i < n; i++)
        ary[i] = Integer.parseInt(line1[i]); int i = 0; int i = 0; i 0 i < n i n i++ i++ i ary[i] = Integer.parseInt(line1[i]); ary[i] = Integer.parseInt(line1[i]) ary[i] ary i Integer.parseInt(line1[i]) Integer.parseInt Integer line1[i] line1 i int min = 4950; min 4950 for(int i = 0; i < n; i++){
            int a = 0;
            int b = 0;
            for(int j = 0; j <= i; j++)
            a += ary[j];
            for(int k = i + 1; k < n; k++)
            b += ary[k];
            int c = a - b;
            if(c < 0)
            c = b - a;
            if(c < min)
            min = c;
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            int a = 0;
            int b = 0;
            for(int j = 0; j <= i; j++)
            a += ary[j];
            for(int k = i + 1; k < n; k++)
            b += ary[k];
            int c = a - b;
            if(c < 0)
            c = b - a;
            if(c < min)
            min = c;
        } {
            int a = 0;
            int b = 0;
            for(int j = 0; j <= i; j++)
            a += ary[j];
            for(int k = i + 1; k < n; k++)
            b += ary[k];
            int c = a - b;
            if(c < 0)
            c = b - a;
            if(c < min)
            min = c;
        } int a = 0; a 0 int b = 0; b 0 for(int j = 0; j <= i; j++)
            a += ary[j]; int j = 0; int j = 0; j 0 j <= i j i j++ j++ j a += ary[j]; a += ary[j] a ary[j] ary j for(int k = i + 1; k < n; k++)
            b += ary[k]; int k = i + 1; int k = i + 1; k i + 1 i 1 k < n k n k++ k++ k b += ary[k]; b += ary[k] b ary[k] ary k int c = a - b; c a - b a b if(c < 0)
            c = b - a; c < 0 c 0 c = b - a c b - a b a if(c < min)
            min = c; c < min c min min = c min c 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 = Integer.parseInt(sc.nextLine());
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        int[] ary = new int[n];
        for(int i = 0; i < n; i++)
        ary[i] = Integer.parseInt(line1[i]);
        int min = 4950;
        for(int i = 0; i < n; i++){
            int a = 0;
            int b = 0;
            for(int j = 0; j <= i; j++)
            a += ary[j];
            for(int k = i + 1; k < n; k++)
            b += ary[k];
            int c = a - b;
            if(c < 0)
            c = b - a;
            if(c < min)
            min = c;
        }
        System.out.println(min);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        int[] ary = new int[n];
        for(int i = 0; i < n; i++)
        ary[i] = Integer.parseInt(line1[i]);
        int min = 4950;
        for(int i = 0; i < n; i++){
            int a = 0;
            int b = 0;
            for(int j = 0; j <= i; j++)
            a += ary[j];
            for(int k = i + 1; k < n; k++)
            b += ary[k];
            int c = a - b;
            if(c < 0)
            c = b - a;
            if(c < min)
            min = c;
        }
        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 = Integer.parseInt(sc.nextLine());
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        int[] ary = new int[n];
        for(int i = 0; i < n; i++)
        ary[i] = Integer.parseInt(line1[i]);
        int min = 4950;
        for(int i = 0; i < n; i++){
            int a = 0;
            int b = 0;
            for(int j = 0; j <= i; j++)
            a += ary[j];
            for(int k = i + 1; k < n; k++)
            b += ary[k];
            int c = a - b;
            if(c < 0)
            c = b - a;
            if(c < min)
            min = c;
        }
        System.out.println(min);
    }
}