using System.Runtime.Versioning;

namespace ConsoleApp2
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string[] unos = Console.ReadLine().Split();
            int n = Convert.ToInt32(unos[0]);
            int q = Convert.ToInt32(unos[1]);
            string[] unos2 = Console.ReadLine().Split();
            int[] niz = new int[n];
            int br = 0;
            for(int i = 0; i < n; i++)
            {
                niz[i] = Convert.ToInt32(unos2[i]);
            }
            for(int i = 0; i < q; i++)
            {
                string[] unos3 = Console.ReadLine().Split();
                int l = Convert.ToInt32(unos3[0]);
                int r = Convert.ToInt32(unos3[1]);
                for(int j = l; j < r - 1; j++)
                {
                    if ((niz[j] & niz[j + 1]) > (niz[j] ^ niz[j + 1]))
                        br++;
                    Console.WriteLine(br);
                }
                
            }
        }
    }
}