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.io.*;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.StringTokenizer;
  import java.util.List;
   import java.util.*;
  public  class realfast implements Runnable 
    {
      private static final int INF = (int) 1e9;
      long in= 1000000007;
      long fac[]= new long[1000001];
      long inv[]=new long[1000001];
      long minu = 1000000000;
     
      long maxu = 1000000000;
     
      public  void solve() throws IOException 
      {
         
  
               minu = -minu*1000000;
                maxu = maxu*1000000;
  
        int n = readInt();
        int q= readInt();
        int arr[]=new int[n+1];
        int brr[]=new int[n+1];
        for(int i=1;i<=n;i++)
          arr[i]= readInt();
        for(int i =1;i<=n;i++)
          brr[i]= readInt();
      long sum[]=new long[n+1];
  
      for(int i=1;i<=n;i++)
      {
           sum[i]= sum[i-1]+ brr[i]-arr[i];
      }
      long seg1[]=new long [4*n+10];
      long seg2[]=new long [4*n+10];
      build_max(seg1,sum,1,n,0);
      build_min(seg2,sum,1,n,0);
  
      for(int i =0;i<q;i++)
      {
  
          int l = readInt();
          int r = readInt();
          if((sum[r]-sum[l-1])==0)
          {
               long minwa = query_min(seg2,l,r,1,n,0);
               long maxwa = query_max(seg1,l,r,1,n,0);
               if(minwa-sum[l-1]==0)
                  out.println(maxwa-sum[l-1]);
               else
                  out.println(-1);
  
          }
          else
              out.println(-1);
      }
  
       
  
  
         
  
      }
  
      public void build_max(long seg[] , long sum[] , int left , int right , int index)
      {
          if(left==right)
          {
              seg[index] = sum[left];
              return ;
          }
          int mid = left+(right-left)/2;
  
          build_max(seg,sum,left,mid,2*index+1);
          build_max(seg,sum,mid+1,right,2*index+2);
          seg[index]=Math.max(seg[2*index+1],seg[2*index+2]);
      }
      public void build_min(long seg[] , long sum[] , int left, int right , int index)
      {
          if(left==right)
          {
              seg[index]=sum[left];
              return ;
          }
  
          int mid = left+(right-left)/2;
  
          build_min(seg,sum,left,mid,2*index+1);
          build_min(seg,sum,mid+1,right,2*index+2);
  
          seg[index]=Math.min(seg[2*index+1],seg[2*index+2]);
  
      }
      public long query_max(long seg[] , int l , int r , int left , int right , int index)
      {
          if(left>r||l>right)
              return minu;
  
          if(left>=l&&right<=r)
              return seg[index];
  
          int mid = left+(right-left)/2;
  
          long val1 = query_max(seg,l,r,left,mid,2*index+1);
          long val2 = query_max(seg,l,r,mid+1,right,2*index+2);
  
          return Math.max(val1,val2);
  
  
      }
      public long query_min(long seg[] , int l , int r , int left , int right , int index)
      {
          if(left>r||l>right)
              return maxu;
  
          if(left>=l&&right<=r)
              return seg[index];
  
          int mid = left+(right-left)/2;
  
          long val1 = query_min(seg,l,r,left,mid,2*index+1);
          long val2 = query_min(seg,l,r,mid+1,right,2*index+2);
  
          return Math.min(val1,val2);
  
  
      }
  
  
      
  
     
     
      public long query(long seg[] , int left, int right , int index, int l , int r)
      {   
           long inf = 100000000;
           inf = inf*inf;
          if(left>=l&&right<=r)
          {
              return seg[index];
          }
          if(l>right||left>r)
              return inf;
          int mid = left+(right-left)/2;
          return Math.min(query(seg,left,mid,2*index+1,l,r),query(seg,mid+1,right,2*index+2,l,r));
  
      }
      
      public int value (int seg[], int left , int right ,int index, int l, int r)
      {
              
              if(left>right)
              {
                return -100000000;
              }
              if(right<l||left>r)
                  return -100000000;
              if(left>=l&&right<=r)
                  return seg[index];
              int mid = left+(right-left)/2;
              int val = value(seg,left,mid,2*index+1,l,r);
              int val2 = value(seg,mid+1,right,2*index+2,l,r);
              return Math.max(val,val2);
  
      }
     
      public int gcd(int a , int b )
      {
        if(a<b)
        {
          int t =a;
          a=b;
          b=t;
        }
        if(a%b==0)
          return b ;
        return gcd(b,a%b);
      }
      public long pow(long n , long p,long m)
      {
           if(p==0)
              return 1;
          long val = pow(n,p/2,m);;
          val= (val*val)%m;
          if(p%2==0)
              return val;
          else
              return (val*n)%m;
      }
      
      
      ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      public static void main(String[] args) {
          new Thread(null, new realfast(), "", 128 * (1L << 20)).start();
      }
   
      private static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
      private BufferedReader reader;
      private StringTokenizer tokenizer;
      private PrintWriter out;
   
      @Override
      public void run() {
          try {
              if (ONLINE_JUDGE || !new File("input.txt").exists()) {
                  reader = new BufferedReader(new InputStreamReader(System.in));
                  out = new PrintWriter(System.out);
              } else {
                  reader = new BufferedReader(new FileReader("input.txt"));
                  out = new PrintWriter("output.txt");
              }
              solve();
          } catch (IOException e) {
              throw new RuntimeException(e);
          } finally {
              try {
                  reader.close();
              } catch (IOException e) {
                  // nothing
              }
              out.close();
          }
      }
   
      private String readString() throws IOException {
          while (tokenizer == null || !tokenizer.hasMoreTokens()) {
              tokenizer = new StringTokenizer(reader.readLine());
          }
          return tokenizer.nextToken();
      }
   
      @SuppressWarnings("unused")
      private int readInt() throws IOException {
          return Integer.parseInt(readString());
      }
   
      @SuppressWarnings("unused")
      private long readLong() throws IOException {
          return Long.parseLong(readString());
      }
   
      @SuppressWarnings("unused")
      private double readDouble() throws IOException {
          return Double.parseDouble(readString());
      }
  }
  class edge implements Comparable<edge>{
      int u ;
      int v;
      
      edge(int  u, int v)
      {
         this.u=u;
         this.v=v;
      }
      public int compareTo(edge e)
      {
          return this.v-e.v;
      }
  }