#include #include #include #include using namespace std; int main (int argc, char ** argv) { int m = 0; int q = 0; scanf ("%d %d\n", &m, &q); while (m || q) { long* keys = (long*) malloc(m * sizeof(long)); int i; for (i = 0; i < m; i++) { scanf ("%ld\n", &keys[i]); } for (i = 0; i < q; i++) { int low = 0; int high = 0; scanf ("%d %d\n", &low, &high); low--; map counts; int j; for (j = 0; j < m; j++) { counts[keys[j]] = 0; } for (j = low; j < high; j++) { counts[keys[j]]++; } char output[255] = ""; //ostringstream strr; map::iterator it; for (it = counts.begin(); it != counts.end(); it++) { if (it->second > 1 && output[0] == '\0') { sprintf(output, "%ld", it->first); } } //output = strr.str(); if (output[0] == '\0') strcpy(output, "OK"); printf("%s\n", output); } putchar('\n'); scanf ("%d %d\n", &m, &q); } return 0; }