using System;
using System.Collections.Generic;

class Program {
    static Dictionary<int, int[]> calc = new Dictionary<int, int[]>(); 
    static string[] Ai;
    static int n;

    static int calculate(int start, int end){
        try {
            return calc[start][end-1]; 
        }
        catch{
            try{
                for(int i = calc[start][calc[start].Length-1]+1; i < end; i++) 
                calc[start][i] = calc[start][i-1] & Convert.ToInt32(Ai[i]);

                calc[start][calc[start].Length-1] = end-1;
                return calc[start][end-1];
            }
            catch{
                calc.Add(start, new int[n+1]);
                calc[start][0] = Convert.ToInt32(Ai[0]);
                for(int i = 1; i < end; i++) {
                    calc[start][i] = calc[start][i-1] & Convert.ToInt32(Ai[i]);
                }

                calc[start][calc[start].Length-1] = end-1;
                return calc[start][end-1];
            }
        }
    }

    static void Main(string[] args){
        string[] input = Console.ReadLine().Split(' ');
        n = Convert.ToInt32(input[0]);
        int q = Convert.ToInt32(input[1]);

        Ai = Console.ReadLine().Split(' ');
        for(int i = 0; i < q; i++) {
            input = Console.ReadLine().Split(' ');
            int a = Convert.ToInt32(input[0]);
            int b = Convert.ToInt32(input[1]);

            Console.WriteLine(calculate(a-1, b));
        }
    }
}