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.*;
  import java.util.function.BinaryOperator;
  
  public class E {
      //--------------------------INPUT READER--------------------------------//
      static class fs {
          public BufferedReader br;
          StringTokenizer st = new StringTokenizer("");
  
          public fs() { this(System.in); }
          public fs(InputStream is) {
              br = new BufferedReader(new InputStreamReader(is));
          }
          String next() {
              while (!st.hasMoreTokens()) {
                  try { st = new StringTokenizer(br.readLine()); }
                  catch (IOException e) { e.printStackTrace(); }
              }
              return st.nextToken();
          }
  
          int ni() { return Integer.parseInt(next()); }
          long nl() { return Long.parseLong(next()); }
          double nd() { return Double.parseDouble(next()); }
          String ns() { return next(); }
  
          int[] na(int n) {
              int[] a = new int[n];
              for (int i = 0; i < n; i++) a[i] = ni();
              return a;
          }
      }
      //-----------------------------------------------------------------------//
  
      //---------------------------PRINTER-------------------------------------//
      static class Printer {
          static PrintWriter w;
          public Printer() {this(System.out);}
          public Printer(OutputStream os) {
              w = new PrintWriter(os);
          }
          public void p(int i) {w.println(i);};
          public void p(long l) {w.println(l);};
          public void p(double d) {w.println(d);};
          public void p(String s) { w.println(s);};
          public void pr(int i) {w.println(i);};
          public void pr(long l) {w.print(l);};
          public void pr(double d) {w.print(d);};
          public void pr(String s) { w.print(s);};
          public void pl() {w.println();};
          public void close() {w.close();};
      }
      //------------------------------------------------------------------------//
  
      //--------------------------VARIABLES------------------------------------//
      static fs sc = new fs();
      static OutputStream outputStream = System.out;
      static Printer w = new Printer(outputStream);
      //-----------------------------------------------------------------------//
  
      //--------------------------ADMIN_MODE-----------------------------------//
      private static void ADMIN_MODE() throws IOException {
          if (System.getProperty("ONLINE_JUDGE") == null) {
              w = new Printer(new FileOutputStream("output.txt"));
              sc = new fs(new FileInputStream("input.txt"));
          }
      }
      //-----------------------------------------------------------------------//
  
      //----------------------------START--------------------------------------//
      public static void main(String[] args)
              throws IOException {
  
          ADMIN_MODE();
  
  //        int t = sc.ni();
  //        while(t-->0)
              solve();
  
  
          w.close();
      }
  
      static void solve() throws IOException {
          int n = sc.ni();
          int q = sc.ni();
          long[] a = new long[n];
          long[] b = new long[n];
          for(int i = 0; i < n; i++) a[i] = sc.nl();
          for(int i = 0; i < n; i++) b[i] = sc.nl();
          long[] diff = new long[n];
          for(int i = 0; i < n; i++) {
              diff[i] = a[i]-b[i];
          }
          long[] diffPre = new long[n+1];
          for(int i = 1; i <= n; i++) {
              diffPre[i] = diff[i-1] + diffPre[i-1];
          }
          SparseTable st  = new SparseTable(diffPre, SparseTable.Operation.MAX);
          SparseTable st2 = new SparseTable(diffPre, SparseTable.Operation.MIN);
          while(q-->0) {
              int l = sc.ni();
              int r = sc.ni();
              l--; r--;
              if(diffPre[l] != diffPre[r+1]) {
                  w.p(-1);
                  continue;
              }
              long maxQ = st.query(l, r+1);
              long minQ = st2.query(l, r+1);
              if(maxQ>diffPre[l]) {
                  w.p(-1);
                  continue;
              }
              w.p((diffPre[l]-minQ));
          }
      }
  
      /**
       * Sparse table only supports immutable structures
       * <p>Specify the operation using "Operation" public enum in the constructor</p>
       * Enter the range on which you want to perform query [l, r] both inclusive
       * <p>min, max and gcd queries are constant</p>
       * sum query is logarithmic
       * <p> query index is used to find the index of the min/max values</p>
       */
  // region SparseTable
      static class SparseTable {
  
          // The number of elements in the original input array.
          private int n;
  
          // The maximum power of 2 needed. This value is floor(log2(n))
          private int P;
  
          // Fast log base 2 logarithm lookup table for i, 1 <= i <= n
          private int[] log2;
  
          // The sparse table values.
          private long[][] dp;
  
          // Index Table (IT) associated with the values in the sparse table.
          private int[][] it;
  
          // The various supported query operations on this sparse table.
          public enum Operation {
              MIN,
              MAX,
              SUM,
              MULT,
              GCD
          }
  
          ;
  
          private Operation op;
  
          // All functions must be associative, e.g: a * (b * c) = (a * b) * c for some operation '*'
          private BinaryOperator<Long> sumFn = (a, b) -> a + b;
          private BinaryOperator<Long> minFn = (a, b) -> Math.min(a, b);
          private BinaryOperator<Long> maxFn = (a, b) -> Math.max(a, b);
          private BinaryOperator<Long> multFn = (a, b) -> a * b;
          private BinaryOperator<Long> gcdFn =
                  (a, b) -> {
                      long gcd = a;
                      while (b != 0) {
                          gcd = b;
                          b = a % b;
                          a = gcd;
                      }
                      return Math.abs(gcd);
                  };
  
          public SparseTable(long[] values, Operation op) {
              // TODO(william): Lazily call init in query methods instead of initializing in constructor?
              this.op = op;
              init(values);
          }
  
          private void init(long[] v) {
              n = v.length;
  
              // Tip: to get the floor of the logarithm base 2 in Java you can also do:
              // Integer.numberOfTrailingZeros(Integer.highestOneBit(n)).
              P = (int) (Math.log(n) / Math.log(2));
              dp = new long[P + 1][n];
              it = new int[P + 1][n];
  
              for (int i = 0; i < n; i++) {
                  dp[0][i] = v[i];
                  it[0][i] = i;
              }
  
              log2 = new int[n + 1];
              for (int i = 2; i <= n; i++) {
                  log2[i] = log2[i / 2] + 1;
              }
  
              // Build sparse table combining the values of the previous intervals.
              for (int i = 1; i <= P; i++) {
                  for (int j = 0; j + (1 << i) <= n; j++) {
                      long leftInterval = dp[i - 1][j];
                      long rightInterval = dp[i - 1][j + (1 << (i - 1))];  // [j+(1<<(i-1))] = j + 2^(i-1) // Watch in insertion slides for more info
                      if (op == Operation.MIN) {
                          dp[i][j] = minFn.apply(leftInterval, rightInterval);
                          // Propagate the index of the best value
                          if (leftInterval <= rightInterval) {
                              it[i][j] = it[i - 1][j];
                          } else {
                              it[i][j] = it[i - 1][j + (1 << (i - 1))];
                          }
                      } else if (op == Operation.MAX) {
                          dp[i][j] = maxFn.apply(leftInterval, rightInterval);
                          // Propagate the index of the best value
                          if (leftInterval >= rightInterval) {
                              it[i][j] = it[i - 1][j];
                          } else {
                              it[i][j] = it[i - 1][j + (1 << (i - 1))];
                          }
                      } else if (op == Operation.SUM) {
                          dp[i][j] = sumFn.apply(leftInterval, rightInterval);
                      } else if (op == Operation.MULT) {
                          dp[i][j] = multFn.apply(leftInterval, rightInterval);
                      } else if (op == Operation.GCD) {
                          dp[i][j] = gcdFn.apply(leftInterval, rightInterval);
                      }
                  }
              }
              // Uncomment for debugging
              // printTable();
          }
  
          // For debugging, testing and slides.
          private void printTable() {
              for (long[] r : dp) {
                  for (int i = 0; i < r.length; i++) {
                      System.out.printf("%02d, ", r[i]);
                  }
                  System.out.println();
              }
          }
  
          // Queries [l, r] for the operation set on this sparse table.
          public long query(int l, int r) {
              // Fast queries types, O(1)
              if (op == Operation.MIN) {
                  return query(l, r, minFn);
              } else if (op == Operation.MAX) {
                  return query(l, r, maxFn);
              } else if (op == Operation.GCD) {
                  return query(l, r, gcdFn);
              }
  
              // Slower query types, O(log2(n))
              if (op == Operation.SUM) {
                  return sumQuery(l, r);
              } else {
                  return multQuery(l, r);
              }
          }
  
          public int queryIndex(int l, int r) {
              if (op == Operation.MIN) {
                  return minQueryIndex(l, r);
              } else if (op == Operation.MAX) {
                  return maxQueryIndex(l, r);
              }
              throw new UnsupportedOperationException(
                      "Operation type: " + op + " doesn't support index queries :/");
          }
  
          private int minQueryIndex(int l, int r) {
              int len = r - l + 1;
              int p = log2[len];
              long leftInterval = dp[p][l];
              long rightInterval = dp[p][r - (1 << p) + 1];
              if (leftInterval <= rightInterval) {
                  return it[p][l];
              } else {
                  return it[p][r - (1 << p) + 1];
              }
          }
  
          private int maxQueryIndex(int l, int r) {
              int len = r - l + 1;
              int p = log2[len];
              long leftInterval = dp[p][l];
              long rightInterval = dp[p][r - (1 << p) + 1];
              if (leftInterval >= rightInterval) {
                  return it[p][l];
              } else {
                  return it[p][r - (1 << p) + 1];
              }
          }
  
          // Do sum query [l, r] in O(log2(n)).
          //
          // Perform a cascading query which shrinks the left endpoint while summing over all the intervals
          // which are powers of 2 between [l, r].
          //
          // WARNING: This method can easily produces values that overflow.
          //
          // NOTE: You can achieve a faster time complexity and use less memory with a simple prefix sum
          // array. This method is here more as a proof of concept than for its usefulness.
          private long sumQuery(int l, int r) {
              long sum = 0;
              for (int p = log2[r - l + 1]; l <= r; p = log2[r - l + 1]) {
                  sum += dp[p][l];
                  l += (1 << p);
              }
              return sum;
          }
  
          private long multQuery(int l, int r) {
              long result = 1;
              for (int p = log2[r - l + 1]; l <= r; p = log2[r - l + 1]) {
                  result *= dp[p][l];
                  l += (1 << p);
              }
              return result;
          }
  
          // Do either a min, max or gcd query on the interval [l, r] in O(1).
          //
          // We can get O(1) query by finding the smallest power of 2 that fits within the interval length
          // which we'll call k. Then we can query the intervals [l, l+k] and [r-k+1, r] (which likely
          // overlap) and apply the function again. Some functions (like min and max) don't care about
          // overlapping intervals so this trick works, but for a function like sum this would return the
          // wrong result since it is not an idempotent binary function.
          private long query(int l, int r, BinaryOperator<Long> fn) {
              int len = r - l + 1;
              int p = log2[len];
              return fn.apply(dp[p][l], dp[p][r - (1 << p) + 1]);
          }
      }
  // endregion
  }
  
  