using System;
using System.Collections.Generic;

public class Programme
{
    public static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        long n = long.Parse(input[0]);
        int Q = int.Parse(input[1]);
        input = Console.ReadLine().Split(' ');
        int[] arr = new int[n];
        bool twos = true;
        for (int i = 0; i < n; i++)
        {
            arr[i] = int.Parse(input[i]);
            if (Math.Log2(arr[i]) != Math.Round(Math.Log2(arr[i])))
            {
                twos = false;
            }
        }
        int[] results = new int[Q];
        for (int i = 0; i < Q; i++)
        {
            input = Console.ReadLine().Split(' ');
            int left = int.Parse(input[0]) - 1;
            int right = int.Parse(input[1]) - 1;
            if (twos)
            {
                Dictionary<int, int> powersOfTwo = new Dictionary<int, int>();
                for (int j = left; j <= right; j++)
                {
                    if (powersOfTwo.ContainsKey(arr[j]))
                    {
                        powersOfTwo[arr[j]]++;
                    }
                    else
                    {
                        powersOfTwo[arr[j]] = 1;
                    }
                }
                results[i] = powersOfTwo.MaxBy(val => val.Value).Value;
            }
        }
        foreach (int result in results)
        {
            Console.WriteLine(result);
        }
    }
}