import java.util.Scanner;

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

        int n = sc.nextInt();

        int[] array = new int[n];

        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }

        int ans = 1000000;

        for (int i = 0; i < n; i++) {
            int a = 0;
            int b = 0;

            for (int j = 0; j <= i; j++) {
                a += array[j];
            }

            for (int j = 1; j < n - i; j++) {
                b += array[n - j];
            }

            int min = Math.abs(a - b);

            if (min < ans) {
                ans = min;
            }
        }

        System.out.println(ans);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] array = new int[n];

        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }

        int ans = 1000000;

        for (int i = 0; i < n; i++) {
            int a = 0;
            int b = 0;

            for (int j = 0; j <= i; j++) {
                a += array[j];
            }

            for (int j = 1; j < n - i; j++) {
                b += array[n - j];
            }

            int min = Math.abs(a - b);

            if (min < ans) {
                ans = min;
            }
        }

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

        int n = sc.nextInt();

        int[] array = new int[n];

        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }

        int ans = 1000000;

        for (int i = 0; i < n; i++) {
            int a = 0;
            int b = 0;

            for (int j = 0; j <= i; j++) {
                a += array[j];
            }

            for (int j = 1; j < n - i; j++) {
                b += array[n - j];
            }

            int min = Math.abs(a - b);

            if (min < ans) {
                ans = min;
            }
        }

        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] array = new int[n];

        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }

        int ans = 1000000;

        for (int i = 0; i < n; i++) {
            int a = 0;
            int b = 0;

            for (int j = 0; j <= i; j++) {
                a += array[j];
            }

            for (int j = 1; j < n - i; j++) {
                b += array[n - j];
            }

            int min = Math.abs(a - b);

            if (min < ans) {
                ans = min;
            }
        }

        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] array = new int[n]; array new int[n] n for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            array[i] = sc.nextInt();
        } {
            array[i] = sc.nextInt();
        } array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc int ans = 1000000; ans 1000000 for (int i = 0; i < n; i++) {
            int a = 0;
            int b = 0;

            for (int j = 0; j <= i; j++) {
                a += array[j];
            }

            for (int j = 1; j < n - i; j++) {
                b += array[n - j];
            }

            int min = Math.abs(a - b);

            if (min < ans) {
                ans = min;
            }
        } 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 += array[j];
            }

            for (int j = 1; j < n - i; j++) {
                b += array[n - j];
            }

            int min = Math.abs(a - b);

            if (min < ans) {
                ans = min;
            }
        } {
            int a = 0;
            int b = 0;

            for (int j = 0; j <= i; j++) {
                a += array[j];
            }

            for (int j = 1; j < n - i; j++) {
                b += array[n - j];
            }

            int min = Math.abs(a - b);

            if (min < ans) {
                ans = min;
            }
        } int a = 0; a 0 int b = 0; b 0 for (int j = 0; j <= i; j++) {
                a += array[j];
            } int j = 0; int j = 0; j 0 j <= i j i j++ j++ j {
                a += array[j];
            } {
                a += array[j];
            } a += array[j] a array[j] array j for (int j = 1; j < n - i; j++) {
                b += array[n - j];
            } int j = 1; int j = 1; j 1 j < n - i j n - i n i j++ j++ j {
                b += array[n - j];
            } {
                b += array[n - j];
            } b += array[n - j] b array[n - j] array n - j n j int min = Math.abs(a - b); min Math.abs(a - b) Math.abs Math a - b a b if (min < ans) {
                ans = min;
            } min < ans min ans {
                ans = min;
            } ans = min ans min System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] array = new int[n];

        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }

        int ans = 1000000;

        for (int i = 0; i < n; i++) {
            int a = 0;
            int b = 0;

            for (int j = 0; j <= i; j++) {
                a += array[j];
            }

            for (int j = 1; j < n - i; j++) {
                b += array[n - j];
            }

            int min = Math.abs(a - b);

            if (min < ans) {
                ans = min;
            }
        }

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

        int n = sc.nextInt();

        int[] array = new int[n];

        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }

        int ans = 1000000;

        for (int i = 0; i < n; i++) {
            int a = 0;
            int b = 0;

            for (int j = 0; j <= i; j++) {
                a += array[j];
            }

            for (int j = 1; j < n - i; j++) {
                b += array[n - j];
            }

            int min = Math.abs(a - b);

            if (min < ans) {
                ans = min;
            }
        }

        System.out.println(ans);
    }
} Main
import java.util.Scanner;

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

        int n = sc.nextInt();

        int[] array = new int[n];

        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }

        int ans = 1000000;

        for (int i = 0; i < n; i++) {
            int a = 0;
            int b = 0;

            for (int j = 0; j <= i; j++) {
                a += array[j];
            }

            for (int j = 1; j < n - i; j++) {
                b += array[n - j];
            }

            int min = Math.abs(a - b);

            if (min < ans) {
                ans = min;
            }
        }

        System.out.println(ans);
    }
}