暴力出奇迹。
顺便说一下,不用stringint就A了。。。
先sort,然后一个个枚举过去,发现了就输出并break,因为已经有序了。

#include <cstdio>
#include <algorithm>
unsigned tc(int x) {
    unsigned s = 1;
    for (int i = 1; i <= x; ++i) s *= 10;
    return s;
}
inline int FASTread() {
    char ch = getchar();
    int Sr = 0;
    while (ch < '0' || ch > '9') ch = getchar();
    while (ch >= '0' && ch <= '9') {
        Sr = Sr * 10 + ch - 48;
        ch = getchar();
    }
    return Sr;
}
int main() {
    int n(FASTread()), T(FASTread());
    int x[n + 1], l, q;
    for (int i = 1; i <= n; ++i) {
        x[i] = FASTread();
    }
    std::sort(x + 1, x + n + 1);
    for (int i = 1; i <= T; ++i) {
        l = FASTread(); q = FASTread();
        for (int j = 1; j <= n; ++j) {
            if((x[j] % tc(l)) == q) { 
                printf ("%d\n", x[j]);
                break;
            } else if(j == n) {
                puts("-1");
                break;
            }
        }
    }
}