import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String[] sa = br.readLine().split(" "); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(sa[i]); } sa = br.readLine().split(" "); int[] b = new int[n]; for (int i = 0; i < n; i++) { b[i] = Integer.parseInt(sa[i]); } br.close(); long sum = 0; int[] d = new int[n]; for (int i = 0; i < n; i++) { d[i] = a[i] - b[i]; sum += d[i]; } if (n == 2) { if (sum == 0) { System.out.println(Math.abs(d[0])); } else { System.out.println(-1); } return; } if (sum < 0 || sum % (n - 2) != 0) { System.out.println(-1); return; } long cnt = sum / (n - 2); long sum2 = 0; for (int i = 0; i < n; i++) { long val = (cnt - d[i]); if (val < 0 || val % 2 != 0) { System.out.println(-1); return; } sum2 += val / 2; } if (sum2 == cnt) { System.out.println(cnt); } else { System.out.println(-1); } } }