import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

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

		// 整数の入力
		int n = sc.nextInt();
		int sum = 0;

		Integer array[] = new Integer[n];
		ArrayList<Integer> result = new ArrayList<Integer>();

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

			//総数をとっておく
			sum = sum + array[i];
		}

		//左側の和
		int tmp = 0;

		for (int j = 0; j < n - 1; j++) {
			tmp = tmp + array[j];

			//右側の和
			int right = sum - tmp;
			//差
			int diff = tmp - right;

			if(diff < 0){
				diff = diff * -1;
			}

			result.add(diff);
		}

		Collections.sort(result);

		System.out.println(result.get(0));

		sc.close();
	}
} import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util 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 sum = 0;

		Integer array[] = new Integer[n];
		ArrayList<Integer> result = new ArrayList<Integer>();

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

			//総数をとっておく
			sum = sum + array[i];
		}

		//左側の和
		int tmp = 0;

		for (int j = 0; j < n - 1; j++) {
			tmp = tmp + array[j];

			//右側の和
			int right = sum - tmp;
			//差
			int diff = tmp - right;

			if(diff < 0){
				diff = diff * -1;
			}

			result.add(diff);
		}

		Collections.sort(result);

		System.out.println(result.get(0));

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

		// 整数の入力
		int n = sc.nextInt();
		int sum = 0;

		Integer array[] = new Integer[n];
		ArrayList<Integer> result = new ArrayList<Integer>();

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

			//総数をとっておく
			sum = sum + array[i];
		}

		//左側の和
		int tmp = 0;

		for (int j = 0; j < n - 1; j++) {
			tmp = tmp + array[j];

			//右側の和
			int right = sum - tmp;
			//差
			int diff = tmp - right;

			if(diff < 0){
				diff = diff * -1;
			}

			result.add(diff);
		}

		Collections.sort(result);

		System.out.println(result.get(0));

		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);

		// 整数の入力
		int n = sc.nextInt();
		int sum = 0;

		Integer array[] = new Integer[n];
		ArrayList<Integer> result = new ArrayList<Integer>();

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

			//総数をとっておく
			sum = sum + array[i];
		}

		//左側の和
		int tmp = 0;

		for (int j = 0; j < n - 1; j++) {
			tmp = tmp + array[j];

			//右側の和
			int right = sum - tmp;
			//差
			int diff = tmp - right;

			if(diff < 0){
				diff = diff * -1;
			}

			result.add(diff);
		}

		Collections.sort(result);

		System.out.println(result.get(0));

		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int sum = 0; sum 0 Integer array[] = new Integer[n]; array new Integer[n] n ArrayList<Integer> result = new ArrayList<Integer>(); result new ArrayList<Integer>() for (int i = 0; i < n; i++) {
			array[i] = (sc.nextInt());

			//総数をとっておく
			sum = sum + array[i];
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			array[i] = (sc.nextInt());

			//総数をとっておく
			sum = sum + array[i];
		} {
			array[i] = (sc.nextInt());

			//総数をとっておく
			sum = sum + array[i];
		} array[i] = (sc.nextInt()) array[i] array i (sc.nextInt()) sc.nextInt sc sum = sum + array[i] sum sum + array[i] sum array[i] array i int tmp = 0; tmp 0 for (int j = 0; j < n - 1; j++) {
			tmp = tmp + array[j];

			//右側の和
			int right = sum - tmp;
			//差
			int diff = tmp - right;

			if(diff < 0){
				diff = diff * -1;
			}

			result.add(diff);
		} int j = 0; int j = 0; j 0 j < n - 1 j n - 1 n 1 j++ j++ j {
			tmp = tmp + array[j];

			//右側の和
			int right = sum - tmp;
			//差
			int diff = tmp - right;

			if(diff < 0){
				diff = diff * -1;
			}

			result.add(diff);
		} {
			tmp = tmp + array[j];

			//右側の和
			int right = sum - tmp;
			//差
			int diff = tmp - right;

			if(diff < 0){
				diff = diff * -1;
			}

			result.add(diff);
		} tmp = tmp + array[j] tmp tmp + array[j] tmp array[j] array j int right = sum - tmp; right sum - tmp sum tmp int diff = tmp - right; diff tmp - right tmp right if(diff < 0){
				diff = diff * -1;
			} diff < 0 diff 0 {
				diff = diff * -1;
			} diff = diff * -1 diff diff * -1 diff -1 1 result.add(diff) result.add result diff Collections.sort(result) Collections.sort Collections result System.out.println(result.get(0)) System.out.println System.out System System.out result.get(0) result.get result 0 sc.close() sc.close sc String[] args args public class Main {

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

		// 整数の入力
		int n = sc.nextInt();
		int sum = 0;

		Integer array[] = new Integer[n];
		ArrayList<Integer> result = new ArrayList<Integer>();

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

			//総数をとっておく
			sum = sum + array[i];
		}

		//左側の和
		int tmp = 0;

		for (int j = 0; j < n - 1; j++) {
			tmp = tmp + array[j];

			//右側の和
			int right = sum - tmp;
			//差
			int diff = tmp - right;

			if(diff < 0){
				diff = diff * -1;
			}

			result.add(diff);
		}

		Collections.sort(result);

		System.out.println(result.get(0));

		sc.close();
	}
} public class Main {

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

		// 整数の入力
		int n = sc.nextInt();
		int sum = 0;

		Integer array[] = new Integer[n];
		ArrayList<Integer> result = new ArrayList<Integer>();

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

			//総数をとっておく
			sum = sum + array[i];
		}

		//左側の和
		int tmp = 0;

		for (int j = 0; j < n - 1; j++) {
			tmp = tmp + array[j];

			//右側の和
			int right = sum - tmp;
			//差
			int diff = tmp - right;

			if(diff < 0){
				diff = diff * -1;
			}

			result.add(diff);
		}

		Collections.sort(result);

		System.out.println(result.get(0));

		sc.close();
	}
} Main
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

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

		// 整数の入力
		int n = sc.nextInt();
		int sum = 0;

		Integer array[] = new Integer[n];
		ArrayList<Integer> result = new ArrayList<Integer>();

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

			//総数をとっておく
			sum = sum + array[i];
		}

		//左側の和
		int tmp = 0;

		for (int j = 0; j < n - 1; j++) {
			tmp = tmp + array[j];

			//右側の和
			int right = sum - tmp;
			//差
			int diff = tmp - right;

			if(diff < 0){
				diff = diff * -1;
			}

			result.add(diff);
		}

		Collections.sort(result);

		System.out.println(result.get(0));

		sc.close();
	}
}
