using System;
using System.Collections.Generic;
using System.Linq;


namespace ConsoleApp3
{
    class Program
    {
        
        static long Funkcija(long[] podniz)
        {
            
            Dictionary<long, long> d = new Dictionary<long, long>();

            foreach (long pd in podniz)
            {
                if (d.ContainsKey(pd)) d[pd]++;
                else d[pd] = 1;
               
            }
            long max = 0;
            foreach (KeyValuePair<long, long> par in d)
            {
                if (par.Value > max)
                    max = par.Value;
            }

            return max;
        }
        static void Main()
        {
            string[] s = Console.ReadLine().Split();
            long n = long.Parse(s[0]);
            long q = long.Parse(s[1]);
            string[] s1 = Console.ReadLine().Split();
            long[] a = new long[n];
            for (int i = 0; i < n; i++) a[i] = long.Parse(s1[i]);
            

            List<long> rez = new List<long>();
            for(int i = 0; i< q; i++)
            
            {
                string[] s2 = Console.ReadLine().Split();
                int l = int.Parse(s2[0]);
                int r = int.Parse(s2[1]);

                long[] podniz = a.Skip(l - 1).Take(r - l + 1).ToArray();               

                rez.Add(Funkcija(podniz));
          }
            foreach (long res in rez) Console.WriteLine(res);
 
        }
    }
}