use std::io::stdin;

fn abs(a: isize) -> isize {
    if a < 0 { -a } else { a }
}

fn main() {
    let mut n = String::new();
    stdin().read_line(&mut n).unwrap();
    let n: usize = n.trim().parse().unwrap();

    let mut ws = String::new();
    stdin().read_line(&mut ws).unwrap();
    let ws: Vec<isize> = ws.trim().split_whitespace().flat_map(str::parse).collect();

    let mut l = 0;
    let mut r: isize = ws.clone().into_iter().sum();
    let mut best = r;
    for w in ws.into_iter() {
        l += w;
        r -= w;
        let a = abs(l - r);
        if a < best {
            best = a;
        }
    }
    println!("{}", best);
}
