Under construction

Still being built. Things may change

Unique Encryption Keys

Time limit2sMemory limit128 MB

Summary
For each of up to a million range queries over a sequence of keys, decide if the range has a duplicate and report the smallest repeated key value.
Level

Medium7 of 10

Topics
Segment tree, Binary search, Array, Sorting
Solved
No attempts yet

Problem

The security of many ciphers strongly depends on the fact that the keys are unique and are never re-used. This can be vitally important, since even a relatively strong cipher may be broken if the same key is used to encrypt several different messages.

In this problem, we detect repeated (duplicate) usage of keys. Given a sequence of keys used to encrypt messages, your task is to determine, for a specified interval, whether any key has been used more than once.

Input

The input contains several cipher descriptions. Each description starts with one line containing two integers MM and QQ separated by a space. MM (1≤M≤1061 \le M \le 10^6) is the number of encrypted messages, and QQ (0≤Q≤1060 \le Q \le 10^6) is the number of queries.

Each of the following MM lines contains one integer KiK_i (0≤Ki≤2300 \le K_i \le 2^{30}), the identifier of the key used to encrypt the ii-th message. The next QQ lines each contain one query, given by two integers BjB_j and EjE_j (1≤Bj≤Ej≤M1 \le B_j \le E_j \le M), the interval of messages to check.

There is one empty line after each description. The input is terminated by a line containing two zeros in place of MM and QQ.

Output

For each query, print one line. Print the string OK if all keys used to encrypt messages between BjB_j and EjE_j (inclusive) are pairwise distinct. Otherwise, print the smallest key identifier that occurs at least twice within that interval.

Separate the answers belonging to consecutive descriptions by one empty line.

Examples3

  1. Example 1

    Input
    10 5
    3
    2
    3
    4
    9
    7
    3
    8
    4
    1
    1 3
    2 6
    4 10
    3 7
    2 6
    
    5 2
    1
    2
    3
    1
    2
    2 4
    1 5
    
    0 0
    
    Expected output
    3
    OK
    4
    3
    OK
    
    OK
    1
    
  2. Example 2

    Input
    3 1
    1
    2
    3
    1 3
    
    0 0
    
    Expected output
    OK
    
  3. Example 3

    Input
    6 1
    5
    3
    5
    3
    7
    7
    1 6
    
    0 0
    
    Expected output
    3