T2
模拟水题,按图书编号从小到大排序,然后直接查询判断,不会TLE的
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
using namespace std;
int n,q,len,ans,a[1000006],s;
int main()
{
cin>>n>>q;
rep(i,1,n)cin>>a[i];
sort(a+1,a+1+n);
while(q--){
ans=-1;
cin>>len>>s;
int t=1;
while(len--)t*=10;
rep(i,1,n)
if(a[i]%t==s){
ans=a[i];
break;
}
printf("%d\n",ans);
}
return 0;
}