#include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,a,b) for (int i = (a); i <= (b); ++i) #define FORI(i,n) REP(i,1,n) #define FOR(i,n) REP(i,0,int(n)-1) #define mp make_pair #define pb push_back #define pii pair #define vi vector #define ll long long #define SZ(x) ((int)(x.size())) #define IN(x,y) ((y).find((x)) != (y).end()) #define DBG(v) cerr << #v << " = " << (v) << endl; #define FOREACH(i,t) for (typeof (t.begin()) i = t.begin(); i != t.end(); i++) #define fi first #define se second #define maxn 1000100 #define M (1<<21) int n,q; int next[maxn], k[maxn]; int T[maxn]; int W[2*M+17]; pair tt[maxn]; void add(int pos, int val) { int start = pos; T[start] = val; pos += M; while(pos > 1) { if(T[W[pos]] > val) W[pos] = start; pos >>= 1; } } int getmin(int a, int b) { a += M; b += M; int res = W[a]; while(a+1 < b) { if(a%2 == 0) if(T[res] > T[W[a+1]]) res = W[a+1]; if(b%2 == 1) if(T[res] > T[W[b-1]]) res = W[b-1]; a >>= 1; b >>= 1; } return res; } int main () { while(1) { scanf("%d%d", &n, &q); if(!n) return 0; FOR(i,n) scanf("%d", &k[i]); FOR(i,n) tt[i] = mp(k[i], i); sort(tt,tt+n); FOR(i,n) { if(i+1 < n && tt[i+1].fi == tt[i].fi) next[tt[i].se] = tt[i+1].se; else next[tt[i].se] = n+7; } FOR(i,2*M) W[i] = n+8; T[n+8] = n+10; //FOR(i,n) printf("next[%d] = %d\n", i, next[i]); FOR(i,n) add(i, next[i]); FOR(i,q) { int a,b; scanf("%d%d", &a, &b); int mx = getmin(a-1,b); //printf("mx = %d\n", mx); if(T[mx] < b) printf("%d\n", k[mx]); else printf("OK\n"); } printf("\n"); } return 0; }