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.*;
  import java.text.*;
  
  public class CF_1556_E{
      //SOLUTION BEGIN
      void pre() throws Exception{}
      void solve(int TC) throws Exception{
          int N = ni(), Q = ni();
          long[] A = new long[1+N];
          for(int i = 1; i<= N; i++)A[i] -= nl();
          for(int i = 1; i<= N; i++)A[i] += nl();
          long[] P = new long[1+N];
          for(int i = 1; i<= N; i++)P[i] = P[i-1]+A[i];
  
          MinTree min = new MinTree(P);
          MaxTree max = new MaxTree(P);
          for(int q = 0; q< Q; q++){
              int L = ni(), R = ni();
              long mn = min.query(L, R-1) - P[L-1], mx = max.query(L, R-1)-P[L-1];
              if(mn < 0 || P[R] != P[L-1])pn(-1);
              else pn(mx);
          }
      }
      class MinTree {
          private long initValue(){return IINF;}
          private long update(long oldValue, long newValue){return oldValue+newValue;}
          private long merge(long le, long ri){return Math.min(le, ri);}
          private long initQuery(){return IINF;}
  
          private int m= 1;
          private long[] t;
          public MinTree(int n){
              while(m<n)m<<=1;
              t = new long[m<<1];
              Arrays.fill(t, initValue());
          }
          public MinTree(long[] a){
              while(m<a.length)m<<=1;
              t = new long[m<<1];
              Arrays.fill(t, initValue());
              for(int i = 0; i< a.length; i++)t[i+m] = a[i];
              for(int i = m-1; i>0; i--)t[i] = merge(t[i<<1], t[i<<1|1]);
          }
          public void update(int i, long val){
              t[i += m]  = update(t[i], val);
              for(i>>=1;i>0;i>>=1)t[i] = merge(t[i<<1], t[i<<1|1]);
          }
          public long query(int l, int r){
              long lans = initQuery(), rans = initQuery();
              for(l+=m,r+=m+1;l<r;l>>=1,r>>=1){
                  if((l&1)==1)lans = merge(lans, t[l++]);
                  if((r&1)==1)rans = merge(t[--r], rans);
              }
              return merge(lans, rans);
          }
      }
      class MaxTree {
          private long initValue(){return -IINF;}
          private long update(long oldValue, long newValue){return oldValue+newValue;}
          private long merge(long le, long ri){return Math.max(le,ri);}
          private long initQuery(){return -IINF;}
  
          private int m= 1;
          private long[] t;
          public MaxTree(int n){
              while(m<n)m<<=1;
              t = new long[m<<1];
              Arrays.fill(t, initValue());
          }
          public MaxTree(long[] a){
              while(m<a.length)m<<=1;
              t = new long[m<<1];
              Arrays.fill(t, initValue());
              for(int i = 0; i< a.length; i++)t[i+m] = a[i];
              for(int i = m-1; i>0; i--)t[i] = merge(t[i<<1], t[i<<1|1]);
          }
          public void update(int i, long val){
              t[i += m]  = update(t[i], val);
              for(i>>=1;i>0;i>>=1)t[i] = merge(t[i<<1], t[i<<1|1]);
          }
          public long query(int l, int r){
              long lans = initQuery(), rans = initQuery();
              for(l+=m,r+=m+1;l<r;l>>=1,r>>=1){
                  if((l&1)==1)lans = merge(lans, t[l++]);
                  if((r&1)==1)rans = merge(t[--r], rans);
              }
              return merge(lans, rans);
          }
      }
      //SOLUTION END
      void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
      void exit(boolean b){if(!b)System.exit(0);}
      static void dbg(Object... o){System.err.println(Arrays.deepToString(o));}
      final long IINF = (long)1e15;
      final int INF = (int)1e9+2;
      DecimalFormat df = new DecimalFormat("0.00000000000");
      double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-8;
      static boolean multipleTC = false, memory = true, fileIO = false;
      FastReader in;PrintWriter out;
      void run() throws Exception{
          long ct = System.currentTimeMillis();
          if (fileIO) {
              in = new FastReader("");
              out = new PrintWriter("");
          } else {
              in = new FastReader();
              out = new PrintWriter(System.out);
          }
          //Solution Credits: Taranpreet Singh
          int T = multipleTC? ni():1;
          pre();
          for (int t = 1; t <= T; t++) solve(t);
          out.flush();
          out.close();
          System.err.println(System.currentTimeMillis() - ct);
      }
      public static void main(String[] args) throws Exception{
          if(memory)new Thread(null, new Runnable() {public void run(){try{new CF_1556_E().run();}catch(Exception e){e.printStackTrace();System.exit(1);}}}, "1", 1 << 28).start();
          else new CF_1556_E().run();
      }
      int[][] make(int n, int e, int[] from, int[] to, boolean f){
          int[][] g = new int[n][];int[]cnt = new int[n];
          for(int i = 0; i< e; i++){
              cnt[from[i]]++;
              if(f)cnt[to[i]]++;
          }
          for(int i = 0; i< n; i++)g[i] = new int[cnt[i]];
          for(int i = 0; i< e; i++){
              g[from[i]][--cnt[from[i]]] = to[i];
              if(f)g[to[i]][--cnt[to[i]]] = from[i];
          }
          return g;
      }
      int[][][] makeS(int n, int e, int[] from, int[] to, boolean f){
          int[][][] g = new int[n][][];int[]cnt = new int[n];
          for(int i = 0; i< e; i++){
              cnt[from[i]]++;
              if(f)cnt[to[i]]++;
          }
          for(int i = 0; i< n; i++)g[i] = new int[cnt[i]][];
          for(int i = 0; i< e; i++){
              g[from[i]][--cnt[from[i]]] = new int[]{to[i], i, 0};
              if(f)g[to[i]][--cnt[to[i]]] = new int[]{from[i], i, 1};
          }
          return g;
      }
      int find(int[] set, int u){return set[u] = (set[u] == u?u:find(set, set[u]));}
      int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;}
      long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
      int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
      int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
      void p(Object... o){for(Object oo:o)out.print(oo+" ");}
      void pn(Object... o){for(int i = 0; i< o.length; i++)out.print(o[i]+(i+1 < o.length?" ":"\n"));}
      void pni(Object... o){for(Object oo:o)out.print(oo+" ");out.println();out.flush();}
      String n()throws Exception{return in.next();}
      String nln()throws Exception{return in.nextLine();}
      int ni()throws Exception{return Integer.parseInt(in.next());}
      long nl()throws Exception{return Long.parseLong(in.next());}
      double nd()throws Exception{return Double.parseDouble(in.next());}
  
      class FastReader{
          BufferedReader br;
          StringTokenizer st;
          public FastReader(){
              br = new BufferedReader(new InputStreamReader(System.in));
          }
  
          public FastReader(String s) throws Exception{
              br = new BufferedReader(new FileReader(s));
          }
  
          String next() throws Exception{
              while (st == null || !st.hasMoreElements()){
                  try{
                      st = new StringTokenizer(br.readLine());
                  }catch (IOException  e){
                      throw new Exception(e.toString());
                  }
              }
              return st.nextToken();
          }
  
          String nextLine() throws Exception{
              String str;
              try{
                  str = br.readLine();
              }catch (IOException e){
                  throw new Exception(e.toString());
              }
              return str;
          }
      }
  }