package yukicoder; import java.util.*; public class Q130 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); ArrayList a = new ArrayList<>(); for (int i = 0; i < n; ++i) { a.add(sc.nextInt()); } System.out.println(dfs(a, 30)); } // Suppose that a is sorted static int dfs(ArrayList a, int pos) { if (pos == -1) return 0; ArrayList one = new ArrayList<>(); ArrayList zero = new ArrayList<>(); for (int i = 0; i < a.size(); ++i) { if ((a.get(i) & (1 << pos)) > 0) { one.add(a.get(i)); } else { zero.add(a.get(i)); } } int ans = Integer.MAX_VALUE;// 10,11 if (one.size() == 0) { ans = Math.min(ans, dfs(zero, pos - 1)); } else if (zero.size() == 0) { ans = Math.min(ans, dfs(one, pos - 1)); } else { ans = Math.min(ans, dfs(zero, pos - 1) + (1 << pos)); ans = Math.min(ans, dfs(one, pos - 1) + (1 << pos)); } return ans; } }