import java.io.*; import java.math.MathContext; import java.util.*; public class StrangeTeacher { private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); private static final PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); private static StringTokenizer st; private static int readInt() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return Integer.parseInt(st.nextToken()); } public static void main(String[] args) throws IOException { pw.println(solve()); pw.close(); } private static long solve() throws IOException { int N = readInt(); long[] A = new long[N]; for (int i = 0; i < N; i++) A[i] = readInt(); for (int i = 0; i < N; i++) A[i] -= readInt(); if (N == 2) { if (A[0] + A[1] == 0) return Math.abs(A[0]); else return -1; } long sum = Arrays.stream(A).sum(); if (sum < 0 || sum % (N - 2) != 0) return -1; long operation = sum / (N-2); for (int i = 0; i < N; i++) { if ((operation - A[i]) % 2 != 0 || operation < A[i] ) return -1; } return operation; } }