题目链接:点击这里
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
const int MOD = 10000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int maxn = 1010;
int book[maxn];
bool judge(int x, int y, int z)
{
int ans1 = 0;
int ans2 = 0;
for(int i = 0; i < z; i++)
{
ans1 = ans1*10 + x%10;
x = x/10;
}
for(int i = 0; i < z; i++)
{
ans2 = ans2*10 + y%10;
y = y/10;
}
if(ans1==ans2) return true;
else return false;
}
int main()
{
int n, q, len, reader, ans;
scanf("%d%d", &n, &q);
for(int i = 0; i < n; i++)
scanf("%d", &book[i]);
sort(book, book+n);
while(q--)
{
scanf("%d%d", &len, &reader);
ans = -1;
for(int i = 0; i < n; i++)
{
if(judge(book[i], reader, len))
{
ans = book[i];
break;
}
}
printf("%d\n", ans);
}
return 0;
}