import java.io.*; import java.util.*; import java.math.*; class Main { public static void out (Object o) { System.out.println(o); } public static int solve (int[] levelM , int[] levelE) { int len = levelM.length; Arrays.sort(levelM); for (int i = 0; i < len; i++) { int upIndex = 0; int min = levelM[0] & 0xfff; for (int j = 1; j < len && levelM[0] >> 12 == levelM[j] >> 12; j++) { int f = levelM[j] & 0xfff; if (f < min) { min = f; upIndex = j; } } levelM[upIndex]++; levelM[upIndex] += (levelE[i] >> 1) << 12; Arrays.sort(levelM); } int ret = 0; for (int i = 0; i < len; i++) ret = Math.max(ret , levelM[i] & 0xfff); return ret; } public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int len = Integer.parseInt(br.readLine()); String[] line1 = br.readLine().split(" "); int[] levelM = new int[len]; String[] line2 = br.readLine().split(" "); int[] levelE = new int[len]; for (int i = 0; i < len; i++) { levelM[i] = Integer.parseInt(line1[i]) << 12; levelE[i] = Integer.parseInt(line2[i]); } out(solve(levelM , levelE)); } }