def main():
    _ = int(input())
    A = list(map(int, input().split()))
    ans = 1e10
    for i in range(len(A)+1):
        sum_diff = abs(sum(A[:i]) - sum(A[i:]))
        ans = min(ans, sum_diff)

    print(ans)


if __name__ == '__main__':
    main() def main():
    _ = int(input())
    A = list(map(int, input().split()))
    ans = 1e10
    for i in range(len(A)+1):
        sum_diff = abs(sum(A[:i]) - sum(A[i:]))
        ans = min(ans, sum_diff)

    print(ans) main _ = int(input()) _ int(input()) int input() input A = list(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ans = 1e10 ans 1e10 for i in range(len(A)+1):
        sum_diff = abs(sum(A[:i]) - sum(A[i:]))
        ans = min(ans, sum_diff)

     i range(len(A)+1) range len(A)+1 len(A) len A 1 sum_diff = abs(sum(A[:i]) - sum(A[i:])) sum_diff abs(sum(A[:i]) - sum(A[i:])) abs sum(A[:i]) - sum(A[i:]) sum(A[:i]) sum A[:i] A :i i sum(A[i:]) sum A[i:] A i: i ans = min(ans, sum_diff) ans min(ans, sum_diff) min ans sum_diff print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    _ = int(input())
    A = list(map(int, input().split()))
    ans = 1e10
    for i in range(len(A)+1):
        sum_diff = abs(sum(A[:i]) - sum(A[i:]))
        ans = min(ans, sum_diff)

    print(ans) def main():
    _ = int(input())
    A = list(map(int, input().split()))
    ans = 1e10
    for i in range(len(A)+1):
        sum_diff = abs(sum(A[:i]) - sum(A[i:]))
        ans = min(ans, sum_diff)

    print(ans) main
def main():
    _ = int(input())
    A = list(map(int, input().split()))
    ans = 1e10
    for i in range(len(A)+1):
        sum_diff = abs(sum(A[:i]) - sum(A[i:]))
        ans = min(ans, sum_diff)

    print(ans)


if __name__ == '__main__':
    main()