import java.io.*; import java.util.*; import java.math.*; class Main { static int len; public static void out (Object o) { System.out.println(o); } public static int[] sort (int[] a) { for (int i = 1; i < len; i++) { if (a[0] > a[i]) { int tmp = a[0]; a[0] = a[i]; a[i] = tmp; } } return a; } public static int solve (int[] levelM , int[] levelE) { int ret = Integer.MAX_VALUE , maxI = -1; int[] bk = Arrays.copyOf(levelM , len); main:for (int i = 0; i < len; i++) { int win = 0; PriorityQueue pq = new PriorityQueue(); for (int j = 0; j < len; j++) pq.add(bk[j]); for (int j = i; win++ < len; j++) { j %= len; int p = pq.poll(); p += levelE[j] + 1; if ((p & 0xfff) >= ret) continue main; pq.add(p); } int max = 0; for (int j = 0; j < len; j++) max = Math.max(max , pq.poll() & 0xfff); ret = Math.min(ret , max); } return ret; } public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 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]) >> 1) << 12; } out(solve(levelM , levelE)); } }