description: <image>
  
  William has two arrays a and b, each consisting of n items.
  
  For some segments l..r of these arrays William wants to know if it is possible to equalize the values of items in these segments using a balancing operation. Formally, the values are equalized if for each i from l to r holds a_i = b_i.
  
  To perform a balancing operation an even number of indices must be selected, such that l ≤ pos_1 < pos_2 < ... < pos_k ≤ r. Next the items of array a at positions pos_1, pos_3, pos_5, ... get incremented by one and the items of array b at positions pos_2, pos_4, pos_6, ... get incremented by one.
  
  William wants to find out if it is possible to equalize the values of elements in two arrays for each segment using some number of balancing operations, and what is the minimal number of operations required for that. Note that for each segment the operations are performed independently.
  
  Input
  
  The first line contains a two integers n and q (2 ≤ n ≤ 10^5, 1 ≤ q ≤ 10^5), the size of arrays a and b and the number of segments.
  
  The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^9).
  
  The third line contains n integers b_1, b_2, ..., b_n (0 ≤ b_i ≤ 10^9).
  
  Each of the next q lines contains two integers l_i and r_i (1 ≤ l_i < r_i ≤ n), the edges of segments.
  
  Output
  
  For each segment output a single number — the minimal number of balancing operations needed or "-1" if it is impossible to equalize segments of arrays.
  
  Example
  
  Input
  
  
  8 5
  0 1 2 9 3 2 7 5
  2 2 1 9 4 1 5 8
  2 6
  1 7
  2 4
  7 8
  5 8
  
  
  Output
  
  
  1
  3
  1
  -1
  -1
  
  Note
  
  For the first segment from 2 to 6 you can do one operation with pos = [2, 3, 5, 6], after this operation the arrays will be: a = [0, 2, 2, 9, 4, 2, 7, 5], b = [2, 2, 2, 9, 4, 2, 5, 8]. Arrays are equal on a segment from 2 to 6 after this operation.
  
  For the second segment from 1 to 7 you can do three following operations: 
  
    1. pos = [1, 3, 5, 6] 
    2. pos = [1, 7] 
    3. pos = [2, 7] 
  
  
  
  After these operations, the arrays will be: a = [2, 2, 2, 9, 4, 2, 7, 5], b = [2, 2, 2, 9, 4, 2, 7, 8]. Arrays are equal on a segment from 1 to 7 after these operations.
  
  For the third segment from 2 to 4 you can do one operation with pos = [2, 3], after the operation arrays will be: a = [0, 2, 2, 9, 3, 2, 7, 5], b = [2, 2, 2, 9, 4, 1, 5, 8]. Arrays are equal on a segment from 2 to 4 after this operation.
  
  It is impossible to equalize the fourth and the fifth segment.
solution: import java.util.*;
  import java.util.Map.Entry;
  
  import java.math.*;
  import java.io.*;
  
  public class Main {
  	public static void main(String[] args) throws FileNotFoundException {
  		InputReader in = new InputReader(System.in);
  		// Scanner in = new Scanner(System.in);
  		// Scanner in = new Scanner(new BufferedReader(new
  		// InputStreamReader(System.in)));
  		PrintWriter out = new PrintWriter(System.out);
  		// InputReader in = new InputReader(new
  		// File("ethan_traverses_a_tree.txt"));
  		// PrintWriter out = new PrintWriter(new
  		// File("ethan_traverses_a_tree-output.txt"));
  
  		int n = in.nextInt();
  		int q = in.nextInt();
  		int[] a = new int[n];
  		int[] b = new int[n];
  		for (int i = 0; i < n; i++) {
  			a[i] = in.nextInt();
  		}
  		for (int i = 0; i < n; i++) {
  			b[i] = in.nextInt();
  		}
  		long[] c = new long[n];
  		long[] sum = new long[n];
  		for (int i = 0; i < n; i++) {
  			c[i] = b[i] - a[i];
  
  			if (i == 0) {
  				sum[i] = c[i];
  			} else {
  				sum[i] = sum[i - 1] + c[i];
  			}
  		}
  
  		SegmentTree stsig = new SegmentTree(n, c);
  		SegmentTree stsum = new SegmentTree(n, sum);
  
  		for (int p = 0; p < q; p++) {
  			int l = in.nextInt();
  			int r = in.nextInt();
  
  			long ans = -1;
  			if (stsig.querySum(l, r) == 0) {
  				long presum = 0;
  				if (l > 1) {
  					presum = stsig.querySum(1, l - 1);
  				}
  
  				long rangesummin = stsum.queryMin(l, r) - presum;
  				if (rangesummin >= 0) {
  					ans = stsum.queryMax(l, r) - presum;
  				}
  			}
  
  			out.printf("%d\n", ans);
  		}
  
  		out.close();
  	}
  
  	static class SegmentTree {
  		private int n;
  
  		// [1, n] is valid
  		private long[] dataMin;
  		private long[] dataMax;
  		private long[] dataSum;
  
  		static final long INF = (long)1 << 60;
  
  		public SegmentTree(int m) {
  			this.n = 1;
  			while (this.n < m) {
  				this.n = this.n * 2;
  			}
  
  			int nn = this.n * 2;
  
  			this.dataMin = new long[nn];
  			this.dataMax = new long[nn];
  			this.dataSum = new long[nn];
  		}
  
  		public SegmentTree(int m, long[] a) { // a[0] .. a[m-1] is valid
  			this(m);
  
  			for (int i = n; i < 2 * n; i++) {
  				int aIndex = i - n;
  				if (aIndex >= m) {
  					dataMin[i] = dataMax[i] = dataSum[i] = 0;
  				} else {
  					dataMin[i] = dataMax[i] = dataSum[i] = a[aIndex];
  				}
  			}
  			for (int i = n - 1; i >= 1; i--) {
  				int leftChild = this.getLeftChild(i);
  				int rightChild = this.getRightChild(i);
  
  				dataMin[i] = Math.min(dataMin[leftChild], this.dataMin[rightChild]);
  				dataMax[i] = Math.max(dataMax[leftChild], this.dataMax[rightChild]);
  				dataSum[i] = dataSum[leftChild] + dataSum[rightChild];
  			}
  		}
  
  		private int getLeftChild(int nowIndex) {
  			return nowIndex * 2;
  		}
  
  		private int getRightChild(int nowIndex) {
  			return nowIndex * 2 + 1;
  		}
  
  		public long querySum(int y1, int y2) {
  			SegmentTreeResult result = this.queryAll(y1, y2);
  			return result.sum;
  		}
  
  		public long queryMin(int y1, int y2) {
  			SegmentTreeResult result = this.queryAll(y1, y2);
  			return result.min;
  		}
  
  		public long queryMax(int y1, int y2) {
  			SegmentTreeResult result = this.queryAll(y1, y2);
  			return result.max;
  		}
  
  		public SegmentTreeResult queryAll(int y1, int y2) {
  			SegmentTreeResult result = this._query(y1, y2, 1, 1, this.n);
  			return result;
  		}
  
  		private SegmentTreeResult _query(int y1, int y2, int nowIndex, int leftBound, int rightBound) {
  			SegmentTreeResult result = new SegmentTreeResult();
  
  			if (y1 <= leftBound && y2 >= rightBound) {
  				result.min = dataMin[nowIndex];
  				result.max = dataMax[nowIndex];
  				result.sum = dataSum[nowIndex];
  
  				// System.out.println("cover " + nowIndex + " " + result.sum);
  				return result;
  			}
  
  			int leftChild = this.getLeftChild(nowIndex);
  			int rightChild = this.getRightChild(nowIndex);
  
  			result.min = SegmentTree.INF;
  			result.max = -SegmentTree.INF;
  			result.sum = 0;
  
  			int mid = leftBound + (rightBound - leftBound) / 2;
  
  			if (y1 <= mid) {
  				SegmentTreeResult leftResult = this._query(y1, y2, leftChild, leftBound, mid);
  
  				result.min = Math.min(result.min, leftResult.min);
  				result.max = Math.max(result.max, leftResult.max);
  				result.sum += leftResult.sum;
  			}
  			if (y2 > mid) {
  				SegmentTreeResult rightResult = this._query(y1, y2, rightChild, mid + 1, rightBound);
  				result.min = Math.min(result.min, rightResult.min);
  				result.max = Math.max(result.max, rightResult.max);
  				result.sum += rightResult.sum;
  			}
  			// System.out.println("nomal " + nowIndex + " " + result.sum);
  			return result;
  		}
  
  		public void set(int y, int val) {
  			this._set(y, val, 1, 1, n);
  		}
  
  		private void _set(int y, int val, int nowIndex, int leftBound, int rightBound) {
  			if (leftBound == rightBound) {
  				dataMin[nowIndex] = dataMax[nowIndex] = dataSum[nowIndex] = val;
  			} else {
  				int leftChild = this.getLeftChild(nowIndex);
  				int rightChild = this.getRightChild(nowIndex);
  				int mid = leftBound + (rightBound - leftBound) / 2;
  
  				if (y <= mid) {
  					this._set(y, val, leftChild, leftBound, mid);
  				} else {
  					this._set(y, val, rightChild, mid + 1, rightBound);
  				}
  
  				dataMin[nowIndex] = Math.min(dataMin[leftChild], dataMin[rightChild]);
  				dataMax[nowIndex] = Math.max(dataMax[leftChild], dataMax[rightChild]);
  				dataSum[nowIndex] = dataSum[leftChild] + dataSum[rightChild];
  			}
  		}
  	}
  
  	static class SegmentTreeResult {
  		public long min;
  		public long max;
  		public long sum;
  	}
  
  	static class InputReader {
  		BufferedReader br;
  		StringTokenizer st;
  
  		public InputReader(File f) {
  			try {
  				br = new BufferedReader(new FileReader(f));
  			} catch (FileNotFoundException e) {
  				e.printStackTrace();
  			}
  		}
  
  		public InputReader(InputStream in) {
  			br = new BufferedReader(new InputStreamReader(in));
  		}
  
  		public String next() {
  			while (st == null || !st.hasMoreTokens()) {
  				try {
  					st = new StringTokenizer(br.readLine());
  				} catch (IOException e) {
  					e.printStackTrace();
  				}
  			}
  			return st.nextToken();
  		}
  
  		public boolean hasNext() {
  			while (st == null || !st.hasMoreTokens()) {
  				String s = null;
  				try {
  					s = br.readLine();
  				} catch (IOException e) {
  					e.printStackTrace();
  				}
  				if (s == null)
  					return false;
  				st = new StringTokenizer(s);
  			}
  			return true;
  		}
  
  		public int nextInt() {
  			return Integer.parseInt(next());
  		}
  
  		public long nextLong() {
  			return Long.parseLong(next());
  		}
  
  		public double nextDouble() {
  			return Double.parseDouble(next());
  		}
  	}
  }