import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int [] in = new int [a];
        int sum = 0;
        for(int i=0;i<a;i++){
                             int b = sc.nextInt();
                             sum+=b;
                             in[i]=sum;
                            }
		int ans = sum;
        for(int i=0;i<a-1;i++){ans=Math.min(ans,Math.max(sum-2*in[i],2*in[i]-sum));
                              }
		System.out.println(ans);
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int [] in = new int [a];
        int sum = 0;
        for(int i=0;i<a;i++){
                             int b = sc.nextInt();
                             sum+=b;
                             in[i]=sum;
                            }
		int ans = sum;
        for(int i=0;i<a-1;i++){ans=Math.min(ans,Math.max(sum-2*in[i],2*in[i]-sum));
                              }
		System.out.println(ans);
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int [] in = new int [a];
        int sum = 0;
        for(int i=0;i<a;i++){
                             int b = sc.nextInt();
                             sum+=b;
                             in[i]=sum;
                            }
		int ans = sum;
        for(int i=0;i<a-1;i++){ans=Math.min(ans,Math.max(sum-2*in[i],2*in[i]-sum));
                              }
		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int [] in = new int [a];
        int sum = 0;
        for(int i=0;i<a;i++){
                             int b = sc.nextInt();
                             sum+=b;
                             in[i]=sum;
                            }
		int ans = sum;
        for(int i=0;i<a-1;i++){ans=Math.min(ans,Math.max(sum-2*in[i],2*in[i]-sum));
                              }
		System.out.println(ans);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc int [] in = new int [a]; in new int [a] a int sum = 0; sum 0 for(int i=0;i<a;i++){
                             int b = sc.nextInt();
                             sum+=b;
                             in[i]=sum;
                            } int i=0; int i=0; i 0 i<a i a i++ i++ i {
                             int b = sc.nextInt();
                             sum+=b;
                             in[i]=sum;
                            } {
                             int b = sc.nextInt();
                             sum+=b;
                             in[i]=sum;
                            } int b = sc.nextInt(); b sc.nextInt() sc.nextInt sc sum+=b sum b in[i]=sum in[i] in i sum int ans = sum; ans sum for(int i=0;i<a-1;i++){ans=Math.min(ans,Math.max(sum-2*in[i],2*in[i]-sum));
                              } int i=0; int i=0; i 0 i<a-1 i a-1 a 1 i++ i++ i {ans=Math.min(ans,Math.max(sum-2*in[i],2*in[i]-sum));
                              } {ans=Math.min(ans,Math.max(sum-2*in[i],2*in[i]-sum));
                              } ans=Math.min(ans,Math.max(sum-2*in[i],2*in[i]-sum)) ans Math.min(ans,Math.max(sum-2*in[i],2*in[i]-sum)) Math.min Math ans Math.max(sum-2*in[i],2*in[i]-sum) Math.max Math sum-2*in[i] sum 2*in[i] 2 in[i] in i 2*in[i]-sum 2*in[i] 2 in[i] in i sum 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 a = sc.nextInt();
		int [] in = new int [a];
        int sum = 0;
        for(int i=0;i<a;i++){
                             int b = sc.nextInt();
                             sum+=b;
                             in[i]=sum;
                            }
		int ans = sum;
        for(int i=0;i<a-1;i++){ans=Math.min(ans,Math.max(sum-2*in[i],2*in[i]-sum));
                              }
		System.out.println(ans);
	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int [] in = new int [a];
        int sum = 0;
        for(int i=0;i<a;i++){
                             int b = sc.nextInt();
                             sum+=b;
                             in[i]=sum;
                            }
		int ans = sum;
        for(int i=0;i<a-1;i++){ans=Math.min(ans,Math.max(sum-2*in[i],2*in[i]-sum));
                              }
		System.out.println(ans);
	}
} Main
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int [] in = new int [a];
        int sum = 0;
        for(int i=0;i<a;i++){
                             int b = sc.nextInt();
                             sum+=b;
                             in[i]=sum;
                            }
		int ans = sum;
        for(int i=0;i<a-1;i++){ans=Math.min(ans,Math.max(sum-2*in[i],2*in[i]-sum));
                              }
		System.out.println(ans);
	}
}
