using System;
using System.Linq;

namespace Test
{
    static class Program
    {
        static void Main(string[] args)
        {
            int[] A, _ = Console.ReadLine().Split(' ').Select(v => int.Parse(v));
            int N = _[0], Q = _[1];
            A = Console.ReadLine().Split(' ').Select(v => int.Parse(v));
            for (int i = 0; i < Q; i++)
            {
                _ = Console.ReadLine().Split(' ').Select(v => int.Parse(v));
                int L = _[0], R = _[1], V = -1;
                for (int j = L - 1; j < R; j++)
                    V &= A[j];
                Console.WriteLine(V);
            }
        }
    }
}