#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int IFhave(int a[], int length, int reader, int n)
{
	int flag = 0;
	int m;
	for (int i = 1; i <= n; i++)
	{
		m = pow(10, length);
		if ((a[i] - reader) % m == 0)
		{
		return a[i];
		flag = 1;
		break;
		}
	}
	if (flag == 0)
	{
		return -1;
	}
    return -1;
}

int main()
{
	int n; int q; cin >> n >> q;
	int Book[1000]; int reader;int length;

	for (int i = 1; i <= n; i++)
	{
		cin >> Book[i];
	}
	sort(Book + 1, Book + n + 1);
	for (int j = 1; j <= q; j++)
	{
		cin >> length >> reader;
		b[j]= IFhave(Book, length, reader, n);
		
	}
    for(int j=1;j<=q;j++)
    {
        cout<<b[j]<<endl;
        
    }
	return 0;


}