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


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

            foreach (long pd in podniz)
            {
                if (d.ContainsKey(pd)) d[pd]++;
                else d[pd] = 1;
                if (d[pd] > max)
                    max = d[pd];
            }

            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]);

                var podniz = a.Skip(l - 1).Take(r - l + 1);

                rez.Add(Funkcija(a, l, r));
                

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



        }
    }
}