import bisect def read_data(): N = int(input()) As = list(map(int, input().split())) return N, As def solve(N, As): As = list(set(As)) As.sort() maxA = As[-1] if maxA == 0: return 0 idx = 1 << (len(bin(maxA)) - 2) return divq(As, idx, 0, len(As)) def divq(As, idx, begin, end): if idx == 1 or end <= begin: return 0 new_idx = idx >> 1 if not(As[end-1] & new_idx) or As[begin] & new_idx: return divq(As, new_idx, begin, end) mid = bisect.bisect_left(As, (As[begin]&(-idx))+new_idx, begin, end) return new_idx + min(divq(As, new_idx, begin, mid), divq(As, new_idx, mid, end)) N, As = read_data() print(solve(N, As))