def popcount(n): c=(n&0x5555555555555555)+((n>>1)&0x5555555555555555) c=(c&0x3333333333333333)+((c>>2)&0x3333333333333333) c=(c&0x0f0f0f0f0f0f0f0f)+((c>>4)&0x0f0f0f0f0f0f0f0f) c=(c&0x00ff00ff00ff00ff)+((c>>8)&0x00ff00ff00ff00ff) c=(c&0x0000ffff0000ffff)+((c>>16)&0x0000ffff0000ffff) c=(c&0x00000000ffffffff)+((c>>32)&0x00000000ffffffff) return c N = int(input()) R = list(map(int,input().split())) if N >= 26: print(0) exit() S = [] # 🐜本 p.144 k = N // 2 comb = (1 << k) - 1 while comb < (1 << N): r = 0 for j in range(N): if (comb >> j) & 1: r += R[j] S.append(r) x = comb & -comb y = comb + x comb = (((comb & ~y) // x) >> 1) | y ans = 800000 S.sort() le = len(S) for i in range(le - 1): ans = min(ans,S[i + 1] - S[i]) print(ans)