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.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.Random;
import java.util.*;

public class CutAnsStick implements Runnable {

   int[][] counts;

   // Use Randomized Algo (Time Complexity[nLog(n) + Q(Log(n)^2)]
   void solve() throws IOException {
      int n = ri(), q = ri();
      int[] arr = iArr(n);
      counts = new int[n][];
      int[] total = iArr(n);
      for (int i = 0; i < n; i++) {
         arr[i] = ri() - 1;
         total[arr[i]]++;
      }

      for (int i = 0; i < n; i++) {
         if (total[i] > 0) {
            counts[i] = new int[total[i]];
         }
      }

      for (int i = 0; i < n; i++) {
         int curr = arr[i];
         counts[curr][total[curr] - 1] = i;
         total[curr]--;
      }

      for (int i = 0; i < n; i++) {
         if (counts[i] != null) {
            Arrays.sort(counts[i]);
         }
      }

      while (q-- > 0) {
         int l = ri() - 1, r = ri() - 1;

         // Get 30 random numbers
         Set<Integer> set = new HashSet<>();
         for (int i = 0; i < 30; i++) {
            set.add(arr[getRandom(l, r)]);
         }

         // Check the count of each element and find max
         int max = 1;

         for (int ele : set) {
            int[] curr = counts[ele];
            int count = upperBound(curr, r) - lowerBound(curr, l);
            max = max(max, count);
         }

         int wid = r - l + 1;
         int ans = 0;
         int start = 0, end = max;
         while (start <= end) {
            int mid = (start + end) >> 1; // The number of partitions
            int rem = wid - mid;
            int leftOver = max - mid;
            int allowed = (rem + 1) / 2;
            if (allowed >= leftOver) {
               ans = mid;
               end = mid - 1;
            } else
               start = mid + 1;
         }
         ans++;
         // Answer is just really max(max - (width - max), 1)
         sbr.append(ans).append("\n");
      }

      print(sbr.toString());
   }

   int lowerBound(int[] arr, int val) {
      int l = -1, r = arr.length;
      while (l + 1 < r) {
         int mid = (r + l) >> 1;
         if (arr[mid] >= val)
            r = mid;
         else
            l = mid;
      }
      return r;
   }

   int upperBound(int[] arr, int val) {
      int l = -1, r = arr.length;
      while (l + 1 < r) {
         int mid = (r + l) >> 1;
         if (arr[mid] <= val) {
            l = mid;
         } else {
            r = mid;
         }
      }
      return l + 1;
   }

   /************************************************************************************************************************************************/
   // Time Complexity [ QLog(Q) + ]
   void solveMoAlgo() throws IOException {
      int n = ri(), q = ri();
      int[] arr = iArr(n);
      Query[] queries = new Query[q];
      for (int i = 0; i < n; i++) {
         arr[i] = ri();
      }
      for (int i = 0; i < q; i++) {
         queries[i] = new Query(ri() - 1, ri(), i);
      }

      int sqr = (int) Math.sqrt(q);
      // Sort the queries
      Arrays.sort(queries, (o1, o2) -> {
         if (o1.l / sqr != o2.l / sqr)
            return Integer.compare(o1.l / sqr, o2.l / sqr);
         // To make it even more faster
         // If div by block is odd then sort the right index in ascending order
         // else descending order
         if ((o1.l / sqr & 1) == 1)
            return Integer.compare(o1.r, o2.r);
         return Integer.compare(o2.r, o1.r);
      });

      int leftPointer = 0, rightPointer = 0;
      int[] counts = iArr(n + 1);

      for (Query query : queries) {
         int l = query.l, r = query.r;
         while (leftPointer > query.l) {
            leftPointer--;
            counts[arr[leftPointer]]++;
         }

         while (rightPointer < query.r) {
            counts[arr[rightPointer]]++;
            rightPointer++;
         }

         while (rightPointer > query.r) {
            rightPointer--;
            counts[arr[rightPointer]]--;
         }

         while (leftPointer < query.l) {
            counts[arr[leftPointer]]--;
            leftPointer++;
         }

         // Choose 30 random numbers and find max frequency
         int maxFreq = 1;
         for (int i = 0; i < 30; i++) {
            maxFreq = max(maxFreq, counts[arr[getRandom(l, r - 1)]]);
         }

         query.res = max(1, maxFreq - (r - l - maxFreq));
      }
      int[] ans = iArr(q);
      for (Query qu : queries) {
         ans[qu.index] = qu.res;
      }

      Arrays.stream(ans).forEach(o -> sbr.append(o).append("\n"));
      println(sbr.toString());
   }

   class Query {
      int l, r, index, res = 1;

      public Query(int l, int r, int i) {
         this.l = l;
         this.r = r;
         this.index = i;
      }
   }

   /************************************************************************************************************************************************/
   public static void main(String[] args) throws IOException {
      new Thread(null, new CutAnsStick(), "1").start();
   }

   static PrintWriter out = new PrintWriter(System.out);
   static Reader read = new Reader();
   static StringBuilder sbr = new StringBuilder();
   static int mod = (int) 1e9 + 7;
   static int dmax = Integer.MAX_VALUE;
   static long lmax = Long.MAX_VALUE;
   static int dmin = Integer.MIN_VALUE;
   static long lmin = Long.MIN_VALUE;

   @Override
   public void run() {
      try {
         // solve();
         solveMoAlgo();
         out.close();
      } catch (IOException e) {
         e.printStackTrace();
         System.exit(1);
      }
   }

   static class Reader {
      private byte[] buf = new byte[1024];
      private int index;
      private InputStream in;
      private int total;

      public Reader() {
         in = System.in;
      }

      public int scan() throws IOException {
         if (total < 0)
            throw new InputMismatchException();
         if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0)
               return -1;
         }
         return buf[index++];
      }

      public int intNext() throws IOException {
         int integer = 0;
         int n = scan();
         while (isWhiteSpace(n))
            n = scan();
         int neg = 1;
         if (n == '-') {
            neg = -1;
            n = scan();
         }
         while (!isWhiteSpace(n)) {
            if (n >= '0' && n <= '9') {
               integer *= 10;
               integer += n - '0';
               n = scan();
            } else
               throw new InputMismatchException();
         }
         return neg * integer;
      }

      public double doubleNext() throws IOException {
         double doub = 0;
         int n = scan();
         while (isWhiteSpace(n))
            n = scan();
         int neg = 1;
         if (n == '-') {
            neg = -1;
            n = scan();
         }
         while (!isWhiteSpace(n) && n != '.') {
            if (n >= '0' && n <= '9') {
               doub *= 10;
               doub += n - '0';
               n = scan();
            } else
               throw new InputMismatchException();
         }
         if (n == '.') {
            n = scan();
            double temp = 1;
            while (!isWhiteSpace(n)) {
               if (n >= '0' && n <= '9') {
                  temp /= 10;
                  doub += (n - '0') * temp;
                  n = scan();
               } else
                  throw new InputMismatchException();
            }
         }
         return doub * neg;
      }

      public String read() throws IOException {
         StringBuilder sb = new StringBuilder();
         int n = scan();
         while (isWhiteSpace(n))
            n = scan();
         while (!isWhiteSpace(n)) {
            sb.append((char) n);
            n = scan();
         }
         return sb.toString();
      }

      private boolean isWhiteSpace(int n) {
         if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
            return true;
         return false;
      }
   }

   static void shuffle(int[] aa) {
      int n = aa.length;
      Random rand = new Random();
      for (int i = 1; i < n; i++) {
         int j = rand.nextInt(i + 1);
         int tmp = aa[i];
         aa[i] = aa[j];
         aa[j] = tmp;
      }
   }

   static void shuffle(int[][] aa) {
      int n = aa.length;
      Random rand = new Random();
      for (int i = 1; i < n; i++) {
         int j = rand.nextInt(i + 1);
         int first = aa[i][0];
         int second = aa[i][1];
         aa[i][0] = aa[j][0];
         aa[i][1] = aa[j][1];
         aa[j][0] = first;
         aa[j][1] = second;
      }
   }

   static void print(Object object) {
      out.print(object);
   }

   static void println(Object object) {
      out.println(object);
   }

   static int[] iArr(int len) {
      return new int[len];
   }

   static long[] lArr(int len) {
      return new long[len];
   }

   static long min(long a, long b) {
      return Math.min(a, b);
   }

   static int min(int a, int b) {
      return Math.min(a, b);
   }

   static long max(Long a, Long b) {
      return Math.max(a, b);
   }

   static int max(int a, int b) {
      return Math.max(a, b);
   }

   static int ri() throws IOException {
      return read.intNext();
   }

   static long rl() throws IOException {
      return Long.parseLong(read.read());
   }

   static String rs() throws IOException {
      return read.read();
   }

   static char rc() throws IOException {
      return rs().charAt(0);
   }

   static double rd() throws IOException {
      return read.doubleNext();
   }

   static int getRandom(int l, int r) {
      return l + (int) (Math.random() * (r - l + 1));
   }

   static int lowerbound(ArrayList<Integer> arr, int target) {
      int l = 0;
      int r = arr.size() - 1;
      int mid;
      while (l < r) {
         mid = (l + r) >> 1;
         if (arr.get(mid) >= target)
            r = mid;
         else
            l = mid + 1;
      }
      return l;
   }

   static int upperbound(ArrayList<Integer> arr, int target) {
      int l = 0;
      int r = arr.size() - 1;
      int mid;
      while (l < r) {
         mid = (l + r + 1) >> 1;
         if (arr.get(mid) > target)
            r = mid - 1;
         else
            l = mid;
      }
      return l;
   }
}
