Baby Ehab has a piece of Cut and Stick with an array a of length n written on it. He plans to grab a pair of scissors and do the following to it:

  * pick a range (l, r) and cut out every element a_l, a_{l + 1}, ..., a_r in this range; 
  * stick some of the elements together in the same order they were in the array; 
  * end up with multiple pieces, where every piece contains some of the elements and every element belongs to some piece. 



More formally, he partitions the sequence a_l, a_{l + 1}, ..., a_r into subsequences. He thinks a partitioning is beautiful if for every piece (subsequence) it holds that, if it has length x, then no value occurs strictly more than ⌈ x/2 ⌉ times in it.

He didn't pick a range yet, so he's wondering: for q ranges (l, r), what is the minimum number of pieces he needs to partition the elements a_l, a_{l + 1}, ..., a_r into so that the partitioning is beautiful.

A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly zero) elements. Note that it does not have to be contiguous.

Input

The first line contains two integers n and q (1 ≤ n,q ≤ 3 ⋅ 10^5) — the length of the array a and the number of queries.

The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_i ≤ n) — the elements of the array a.

Each of the next q lines contains two integers l and r (1 ≤ l ≤ r ≤ n) — the range of this query.

Output

For each query, print the minimum number of subsequences you need to partition this range into so that the partitioning is beautiful. We can prove such partitioning always exists.

Example

Input


6 2
1 3 2 3 3 2
1 6
2 5


Output


1
2

Note

In the first query, you can just put the whole array in one subsequence, since its length is 6, and no value occurs more than 3 times in it.

In the second query, the elements of the query range are [3,2,3,3]. You can't put them all in one subsequence, since its length is 4, and 3 occurs more than 2 times. However, you can partition it into two subsequences: [3] and [2,3,3].
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.function.BiFunction;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author koneko096
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    DCutAndStick solver = new DCutAndStick();
    solver.solve(1, in, out);
    out.close();
  }

  static class DCutAndStick {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
      int N = in.nextInt(), Q = in.nextInt();

      List<Integer>[] pos = new List[N + 1];
      for (int i = 0; i <= N; i++) {
        pos[i] = new ArrayList<>();
        pos[i].add(-1);
      }

      Pair<Integer, Integer>[] A = new Pair[N];
      for (int i = 0; i < N; i++) {
        Pair<Integer, Integer> val = Pair.of(in.nextInt(), 1);
        A[i] = val;
        pos[val.getKey()].add(i);
      }

      SegmentTree<Pair<Integer, Integer>> st = new SegmentTree<>(N, Pair.of(-1, 0), this::merger);
      st.build(A);

      while (Q-- > 0) {
        int l = in.nextInt() - 1, r = in.nextInt() - 1;
        int candidate = st.query(l, r).getKey();
        if (candidate < 0) {
          out.println(1);
          continue;
        }

        int len = pos[candidate].size();
        int lb = BinarySearch.lowerBound(pos[candidate], len, l) - 1;
        int ub = BinarySearch.upperBound(pos[candidate], len, r) - 1;
        int freq = (ub - lb);
//            if (N == MaxN && A[0].getKey() == 1) out.println("Freq: "+freq);

        if (freq * 2 <= (r - l + 2)) {
          out.println(1);
          continue;
        }

        int good = (r - l + 1) - freq;
        freq -= good + 1;
        out.println(freq + 1);
      }
    }

    private Pair<Integer, Integer> merger(Pair<Integer, Integer> lhs, Pair<Integer, Integer> rhs) {
      if (lhs.getKey().equals(rhs.getKey())) {
        return Pair.of(lhs.getKey(), lhs.getValue() + rhs.getValue());
      }
      if (lhs.getValue().compareTo(rhs.getValue()) > 0) {
        return Pair.of(lhs.getKey(), lhs.getValue() - rhs.getValue());
      }
      return Pair.of(rhs.getKey(), rhs.getValue() - lhs.getValue());
    }

  }

  static class BinarySearch {
    public static <T extends Comparable<T>> int lowerBound(List<T> list, int length, T value) {
      int low = 0;
      int high = length;
      while (low < high) {
        final int mid = (low + high) / 2;
        if (value.compareTo(list.get(mid)) < 1) {
          high = mid;
        } else {
          low = mid + 1;
        }
      }
      return low;
    }

    public static <T extends Comparable<T>> int upperBound(List<T> list, int length, T value) {
      int low = 0;
      int high = length;
      while (low < high) {
        final int mid = (low + high) / 2;
        if (value.compareTo(list.get(mid)) < 0) {
          high = mid;
        } else {
          low = mid + 1;
        }
      }
      return low;
    }

  }

  static class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

  }

  static class SegmentTree<T> {
    private int N;
    private List<T> tree;
    private T initVal;
    private BiFunction<T, T, T> merge;

    public SegmentTree(int n, T initVal, BiFunction<T, T, T> merge) {
      init(n, initVal, merge);
    }

    void init(int n, T initVal, BiFunction<T, T, T> merge) {
      this.N = n;
      this.merge = merge;
      this.initVal = initVal;
      this.tree = new ArrayList<>(Collections.nCopies(2 * n, initVal));
    }

    public void build(T[] a) {
      for (int i = 0; i < N; i++) {
        tree.set(i + N, a[i]);
      }

      for (int i = N - 1; i > 0; i--) {
        tree.set(i, merge.apply(tree.get(2 * i), tree.get(2 * i + 1)));
      }
    }

    public T query(int l, int r) {
      T res = initVal;
      for (l += N, r += N; l <= r; l >>= 1, r >>= 1) {
        if ((l & 1) == 1) res = merge.apply(res, tree.get(l++));
        if ((r & 1) == 0) res = merge.apply(res, tree.get(r--));
      }
      return res;
    }

  }

  static class Pair<K extends Comparable<K>, V extends Comparable<V>> implements Comparable<Pair<K, V>> {
    private K key;
    private V value;

    public K getKey() {
      return key;
    }

    public V getValue() {
      return value;
    }

    public static <K extends Comparable<K>, V extends Comparable<V>> Pair<K, V> of(K key, V value) {
      return new Pair<>(key, value);
    }

    private Pair(K key, V value) {
      this.key = key;
      this.value = value;
    }

    public String toString() {
      return key + "=" + value;
    }

    public int hashCode() {
      // name's hashCode is multiplied by an arbitrary prime number (13)
      // in order to make sure there is a difference in the hashCode between
      // these two parameters:
      //  name: a  value: aa
      //  name: aa value: a
      return key.hashCode() * 13 + (value == null ? 0 : value.hashCode());
    }

    public boolean equals(Object o) {
      if (this == o) return true;
      if (o instanceof Pair) {
        Pair pair = (Pair) o;
        if (key != null ? !key.equals(pair.key) : pair.key != null) return false;
        if (value != null ? !value.equals(pair.value) : pair.value != null) return false;
        return true;
      }
      return false;
    }

    public int compareTo(Pair<K, V> o) {
      if (this == o) return 0;
      int cmp = key.compareTo(o.getKey());
      if (cmp != 0) return cmp;
      return value.compareTo(o.getValue());
    }

  }
}

