SHANGSI @ 2021-07-21 23:45:19
#include <bits/stdc++.h>
#define N 100+5
using namespace std;
int main(){
int n,q,o;
long long m[N],book[N],bianma[N],len[N];
cin>>n>>q;
for(int op=1;op<=n;++op)
m[op]=1;
for(int a=1;a<=n;++a){
cin>>book[a];
}
sort(book,book+n+1);
for(int c=1;c<=q;++c){
cin>>len[c]>>bianma[c];
for (int j=1;j<=len[c];j++)
m[c]*=10;
}
for(int p=1;p<=n;++p){
for(int g=1;g<=q;++g){
if(book[g]%m[p]==bianma[p]){
cout<<book[g]<<endl;
break;
}
else if(g==n){
cout<<"-1"<<endl;
break;
}
}
}
}