let () =
    let split s =
        let rec loop i cur flag acc =
            if i = String.length s then (
                if flag then cur :: acc else acc
            ) else (
                match flag, s.[i] with
                | true,  ' ' -> loop (i + 1) 0 false (cur :: acc)
                | false, ' ' -> loop (i + 1) 0 false acc
                | true,  v   -> loop (i + 1) (cur * 10 + int_of_char v - 48) true acc
                | false, v   -> loop (i + 1) (cur * 10 + int_of_char v - 48) true acc
            )
        in
        List.rev (loop 0 0 false [])
    in
    let main () =
        let _ = int_of_string (read_line ()) in
        let w = split (read_line ()) in
        let s = List.fold_left (+) 0 w in
        let rec loop acc m = function
            | [] -> m
            | hd :: tl -> 
                let acc = acc + hd in
                let m = min (abs (s - 2 * acc)) m in
                loop acc m tl
        in
        Printf.printf "%d\n" (loop 0 100000000 w)
    in
    main ()