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.io.*;
  
  public class Main {
      public static void main(String args[]) {new Main().run();}
  
      FastReader in = new FastReader();
      PrintWriter out = new PrintWriter(System.out);
      void run() {
          work();
          out.flush();
      }
      long mod=1000000007;
      long gcd(long a,long b) {
          return a==0?b:gcd(b%a,a);
      }
      long inf=Long.MAX_VALUE/3;
      long[] sum1;//最大
      long[] sum2;//最小
      void work() {
          int n=ni(),q=ni();
          sum1=new long[n<<2];
          sum2=new long[n<<2];
          Arrays.fill(sum1,-inf);
          Arrays.fill(sum2,inf);
          long[] A=new long[n];
          for(int i=0;i<n;i++){
              A[i]=-ni();
          }
          for(int i=0;i<n;i++){
              A[i]+=ni();
          }
          long[] sum=new long[n];
          for(int i=0;i<n;i++){
              sum[i]=A[i]+(i==0?0:sum[i-1]);
              add(1,i,sum[i],0,n-1);
          }
          for(;q>0;q--){
              int s=ni()-1,e=ni()-1;
              if(sum[e]-(s==0?0:sum[s-1])!=0){
                  out.println(-1);
                  continue;
              }
              long[] ret=query(1,s,e,0,n-1);
              if(ret[1]-(s==0?0:sum[s-1])<0){
                  out.println(-1);
                  continue;
              }
              out.println(ret[0]-(s==0?0:sum[s-1]));
          }
      }
  
      private long[] query(int node, int s, int e, int l, int r) {
          if(l>=s&&r<=e){
              return new long[]{sum1[node],sum2[node]};
          }
          int m=(l+r)/2;
          long[] ret=null;
          if(m>=s){
              ret=query(node<<1,s,e,l,m);
          }
          if(m+1<=e){
              long[] ret2=query(node<<1|1,s,e,m+1,r);
              if(ret==null){
                  ret=ret2;
              }else{
                  ret[0]=Math.max(ret[0],ret2[0]);
                  ret[1]=Math.min(ret[1],ret2[1]);
              }
          }
          return ret;
      }
  
      private void add(int node, int idx, long v, int l, int r) {
          int m=(l+r)/2;
          if(l==r){
              sum1[node]=v;
              sum2[node]=v;
              return;
          }
          if(idx<=m){
              add(node<<1,idx,v,l,m);
          }else{
              add(node<<1|1,idx,v,m+1,r);
          }
          sum1[node]=Math.max(sum1[node<<1],sum1[node<<1|1]);
          sum2[node]=Math.min(sum2[node<<1],sum2[node<<1|1]);
      }
  
  
  
  
      @SuppressWarnings("unused")
      private ArrayList<Integer>[] ng(int n, int m) {
          ArrayList<Integer>[] graph=(ArrayList<Integer>[])new ArrayList[n];
          for(int i=0;i<n;i++) {
              graph[i]=new ArrayList<>();
          }
          for(int i=1;i<=m;i++) {
              int s=in.nextInt()-1,e=in.nextInt()-1;
              graph[s].add(e);
              graph[e].add(s);
          }
          return graph;
      }
  
      private ArrayList<long[]>[] ngw(int n, int m) {
          ArrayList<long[]>[] graph=(ArrayList<long[]>[])new ArrayList[n];
          for(int i=0;i<n;i++) {
              graph[i]=new ArrayList<>();
          }
          for(int i=1;i<=m;i++) {
              long s=in.nextLong()-1,e=in.nextLong()-1,w=in.nextLong();
              graph[(int)s].add(new long[] {e,w});
              graph[(int)e].add(new long[] {s,w});
          }
          return graph;
      }
  
      private int ni() {
          return in.nextInt();
      }
  
      private long nl() {
          return in.nextLong();
      }
      private double nd() {
          return in.nextDouble();
      }
      private String ns() {
          return in.next();
      }
  
      private long[] na(int n) {
          long[] A=new long[n];
          for(int i=0;i<n;i++) {
              A[i]=in.nextLong();
          }
          return A;
      }
  
      private int[] nia(int n) {
          int[] A=new int[n];
          for(int i=0;i<n;i++) {
              A[i]=in.nextInt();
          }
          return A;
      }
  }
  
  class FastReader
  {
      BufferedReader br;
      StringTokenizer st;
      InputStreamReader input;//no buffer
      public FastReader()
      {
          br=new BufferedReader(new InputStreamReader(System.in));
      }
  
      public FastReader(boolean isBuffer)
      {
          if(!isBuffer){
              input=new InputStreamReader(System.in);
          }else{
              br=new BufferedReader(new InputStreamReader(System.in));
          }
      }
  
      public boolean hasNext(){
          try{
              String s=br.readLine();
              if(s==null){
                  return  false;
              }
              st=new StringTokenizer(s);
          }catch(IOException e){
              e.printStackTrace();
          }
          return true;
      }
  
      public String next()
      {
          if(input!=null){
              try {
                  StringBuilder sb=new StringBuilder();
                  int ch=input.read();
                  while(ch=='\n'||ch=='\r'||ch==32){
                      ch=input.read();
                  }
                  while(ch!='\n'&&ch!='\r'&&ch!=32){
                      sb.append((char)ch);
                      ch=input.read();
                  }
                  return sb.toString();
              }catch (Exception e){
                  e.printStackTrace();
              }
          }
          while(st==null || !st.hasMoreElements())//回车，空行情况
          {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
  
      public int nextInt()
      {
          return (int)nextLong();
      }
  
      public long nextLong() {
          try {
              if(input!=null){
                  long ret=0;
                  int b=input.read();
                  while(b<'0'||b>'9'){
                      b=input.read();
                  }
                  while(b>='0'&&b<='9'){
                      ret=ret*10+(b-'0');
                      b=input.read();
                  }
                  return ret;
              }
          }catch (Exception e){
              e.printStackTrace();
          }
          return Long.parseLong(next());
      }
  
      public double nextDouble()
      {
          return Double.parseDouble(next());
      }
  }