
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[] temp = sc.nextLine().split(" ");
		int[] list = new int[n];
		int ans = 0;

		list[0] = Integer.parseInt(temp[0]);
		for(int i = 1; i < n; i++) {

			list[i] = list[i - 1] + Integer.parseInt(temp[i]);
		}

		ans = list[n - 1];
		for(int i = 1; i < n - 1; i++) {

			ans = Math.min(ans, Math.abs((list[n - 1] - list[i]) - list[i]));

		}

		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 n = Integer.parseInt(sc.nextLine());
		String[] temp = sc.nextLine().split(" ");
		int[] list = new int[n];
		int ans = 0;

		list[0] = Integer.parseInt(temp[0]);
		for(int i = 1; i < n; i++) {

			list[i] = list[i - 1] + Integer.parseInt(temp[i]);
		}

		ans = list[n - 1];
		for(int i = 1; i < n - 1; i++) {

			ans = Math.min(ans, Math.abs((list[n - 1] - list[i]) - list[i]));

		}

		System.out.println(ans);

	}
} Main public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		String[] temp = sc.nextLine().split(" ");
		int[] list = new int[n];
		int ans = 0;

		list[0] = Integer.parseInt(temp[0]);
		for(int i = 1; i < n; i++) {

			list[i] = list[i - 1] + Integer.parseInt(temp[i]);
		}

		ans = list[n - 1];
		for(int i = 1; i < n - 1; i++) {

			ans = Math.min(ans, Math.abs((list[n - 1] - list[i]) - list[i]));

		}

		System.out.println(ans);

	} main {

		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		String[] temp = sc.nextLine().split(" ");
		int[] list = new int[n];
		int ans = 0;

		list[0] = Integer.parseInt(temp[0]);
		for(int i = 1; i < n; i++) {

			list[i] = list[i - 1] + Integer.parseInt(temp[i]);
		}

		ans = list[n - 1];
		for(int i = 1; i < n - 1; i++) {

			ans = Math.min(ans, Math.abs((list[n - 1] - list[i]) - list[i]));

		}

		System.out.println(ans);

	} 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[] temp = sc.nextLine().split(" "); temp sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " int[] list = new int[n]; list new int[n] n int ans = 0; ans 0 list[0] = Integer.parseInt(temp[0]) list[0] list 0 Integer.parseInt(temp[0]) Integer.parseInt Integer temp[0] temp 0 for(int i = 1; i < n; i++) {

			list[i] = list[i - 1] + Integer.parseInt(temp[i]);
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {

			list[i] = list[i - 1] + Integer.parseInt(temp[i]);
		} {

			list[i] = list[i - 1] + Integer.parseInt(temp[i]);
		} list[i] = list[i - 1] + Integer.parseInt(temp[i]) list[i] list i list[i - 1] + Integer.parseInt(temp[i]) list[i - 1] list i - 1 i 1 Integer.parseInt(temp[i]) Integer.parseInt Integer temp[i] temp i ans = list[n - 1] ans list[n - 1] list n - 1 n 1 for(int i = 1; i < n - 1; i++) {

			ans = Math.min(ans, Math.abs((list[n - 1] - list[i]) - list[i]));

		} int i = 1; int i = 1; i 1 i < n - 1 i n - 1 n 1 i++ i++ i {

			ans = Math.min(ans, Math.abs((list[n - 1] - list[i]) - list[i]));

		} {

			ans = Math.min(ans, Math.abs((list[n - 1] - list[i]) - list[i]));

		} ans = Math.min(ans, Math.abs((list[n - 1] - list[i]) - list[i])) ans Math.min(ans, Math.abs((list[n - 1] - list[i]) - list[i])) Math.min Math ans Math.abs((list[n - 1] - list[i]) - list[i]) Math.abs Math (list[n - 1] - list[i]) - list[i] (list[n - 1] - list[i]) list[n - 1] list n - 1 n 1 list[i] list i list[i] list i 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 = Integer.parseInt(sc.nextLine());
		String[] temp = sc.nextLine().split(" ");
		int[] list = new int[n];
		int ans = 0;

		list[0] = Integer.parseInt(temp[0]);
		for(int i = 1; i < n; i++) {

			list[i] = list[i - 1] + Integer.parseInt(temp[i]);
		}

		ans = list[n - 1];
		for(int i = 1; i < n - 1; i++) {

			ans = Math.min(ans, Math.abs((list[n - 1] - list[i]) - list[i]));

		}

		System.out.println(ans);

	}
} public class Main{
	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		String[] temp = sc.nextLine().split(" ");
		int[] list = new int[n];
		int ans = 0;

		list[0] = Integer.parseInt(temp[0]);
		for(int i = 1; i < n; i++) {

			list[i] = list[i - 1] + Integer.parseInt(temp[i]);
		}

		ans = list[n - 1];
		for(int i = 1; i < n - 1; i++) {

			ans = Math.min(ans, Math.abs((list[n - 1] - list[i]) - list[i]));

		}

		System.out.println(ans);

	}
} 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[] temp = sc.nextLine().split(" ");
		int[] list = new int[n];
		int ans = 0;

		list[0] = Integer.parseInt(temp[0]);
		for(int i = 1; i < n; i++) {

			list[i] = list[i - 1] + Integer.parseInt(temp[i]);
		}

		ans = list[n - 1];
		for(int i = 1; i < n - 1; i++) {

			ans = Math.min(ans, Math.abs((list[n - 1] - list[i]) - list[i]));

		}

		System.out.println(ans);

	}
}