using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            int q = int.Parse(s[1]);
            int[] x = new int[n];
            int max = 0;
            int w = 0;
            string[] s1 = Console.ReadLine().Split(' ');
            for (int i = 0; i < n; i++)
            {
                x[i] = int.Parse(s1[i]);
            }
            for (int i = 0; i < q; i++)
            {
                List<int> y = new List<int>();
                string[] s2 = Console.ReadLine().Split(' ');
                int a = int.Parse(s2[0]);
                int b = int.Parse(s2[1]);
                for (int j = a; j <= b; j++)
                {
                    y.Add(x[j - 1]);
                }
                y.Sort();
                int br = 0;
                while (y.Count > 0)
                {
                        w = y[y.Count()-1];
                        if (y.Contains(w))
                        {
                            br++;
                            y.RemoveAt(y.Count() - 1);
                        }
                        max = Math.Max(max, br);

                    
                }
                Console.WriteLine(max);



            }
        }
    }
}