#include<bits/stdc++.h>
using namespace std;
int main() {
long long n, q, x, y, s = 0;
cin >> n >> q;
long long a[n], b[n];
for (long long i = 0; i < n; i++) {
cin >> a[i];
b[i] = i;
}
for (long long i = 0; i < q; i++) {
cin >> x >> y;
for (long long j = 0; j < n; j++) {
if (b[j] != x - 1 && b[j] != y - 1) {
s = max (a[j], s);
} else {
continue;
}
}
cout << s << " \n";
}
return 0;
}