use std::cmp::min;
use std::io::{self, Read};
use num::abs;
macro_rules! input {
($it: expr) => {
$it.next().unwrap().parse().unwrap()
};
($it: expr, $T: ty) => {
$it.next().unwrap().parse::<$T>().unwrap()
};
}
/*
mod classes;
fn main() {
// println!("{}", "-".repeat(20));
classes::c02::task1();
// println!("{}", "-".repeat(20));
}
// */
fn main() {
task();
}
#[allow(dead_code)]
fn task() {
let mut buf = String::new();
io::stdin().read_to_string(&mut buf).unwrap();
let mut it = buf.split_whitespace();
let n: usize = input!(it);
let v: Vec<i32> = (0..n).map(|_| input!(it)).collect();
let sum = v.iter().sum();
println!("{}", apple_div(&v, sum, 0, 0));
}
fn apple_div(v: &Vec<i32>, sum_1: i32, sum_2: i32, i: usize) -> i32 {
if i < v.len() {
let val_1 = apple_div(v, sum_1, sum_2, i+1);
let curr = v[i];
let val_2 = apple_div(v, sum_1 - curr, sum_2 + curr, i+1);
// println!("{} - {}", val_1, val_2);
min(val_1, val_2)
} else {
abs(sum_1-sum_2)
}
}