#include #include #include #include #include using namespace std; #define REP(i,n) for(int i=0; i pii; pii p[1000010]; int tab[2100000]; int old[1000010]; int p2; int wynik; bool ok(int b, int e){ int oldB = b; if(b == e) return true; b += p2; e += p2; int worst = tab[e]; while(b+1 < e){ if(b%2 == 0) worst = max(worst, tab[b+1]); if(e%2 == 1) worst = max(worst, tab[e-1]); b >>= 1; e >>= 1; } if(worst >= 0) wynik = old[worst]; return worst < oldB; } int main() { while(true){ int n, q; scanf("%d%d", &n, &q); if(n == 0 && q == 0) break; REP(i,n) scanf("%d", &a[i]), p[i] = pii(a[i],i); sort(p, p+n); int wsk = 0; REP(i,n) old[i] = a[i]; a[p[0].second] = 0; for(int i=1; i0; --i) tab[i] = max(tab[i<<1], tab[(i<<1) + 1]); while(q--){ int b, e; scanf("%d%d", &b, &e); b--; e--; if(ok(b,e)) printf("OK\n"); else printf("%d\n", wynik); } printf("\n"); } return 0; }