#include <iostream>
#include <vector>
#include <unordered_set>
#include <string>
#include <math.h>
using namespace std;

string u_binarno(int a)
{
	string out = "";\
	int i = 0;
	while(i < 32)
	{
		long long ostatak = a % 2;
		out = to_string(ostatak) + out;
		a /= 2;
		i++;
	}
	return out;
}

int a[200000];
vector<int> nule[32];

int main()
{
	ios_base::sync_with_stdio(false);
	int n, q;
	cin >> n >> q;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	
	for(int i = 0; i < n; i++)
	{
		string str = u_binarno(a[i]);
		for(int j = 0; j < 32; j++)
		{
			int cif = str[32 - j - 1] - '0';
			if(cif == 0)
			{
				nule[j].push_back(i);
			}
		}
	}

	for(int i = 0; i < q; i++)
	{
		int l, d;
		cin >> l >> d;
		l--; d--;
		int rez = 0;
		for(int j = 0; j < 32; j++)
		{
			bool ima_nule = false;
			int lb = 0;
			int db = nule[j].size() - 1;
			while(lb <= db)
			{
				int s = (lb + db) / 2;
				int mid = nule[j][s];
				if(mid <= d && mid >= l)
				{
					ima_nule = true;
					break;
				}
				else if(mid > d)
				{
					db = s - 1;
				}
				else if(mid < l)
				{
					lb = s + 1;
				}
			}
			if(!ima_nule)
			{
				rez += pow(2.0, j);
			}
		}
		cout << rez << "\n";
	}
	return 0;
}