#C7115. Find the Repeating Element

    ID: 50951 Type: Default 1000ms 256MiB

Find the Repeating Element

Find the Repeating Element

You are given an array containing \(N+k\) integers. The array is constructed as follows: it contains every integer from 1 to \(N\) exactly once, except that one special integer is repeated. In other words, one of the numbers appears more than once because it is inserted extra times. You are also given an integer \(k\). When scanning the array from left to right, your task is to find and output the first element whose occurrence count becomes exactly \(k\).

Note: The input guarantees that there is exactly one such element that will reach the count \(k\) while traversing the array.

Formally, if the array is denoted as \(a_1, a_2, \ldots, a_{N+k}\), then find the element \(x\) such that during a left-to-right scan, the count of \(x\) becomes \(k\) before any other element reaches \(k\). Output \(x\).

The following formula explains the relationship between the array length and given parameters:

[ M = N + k ]

where \(M\) is the total number of elements in the array.

inputFormat

The input is read from standard input and has the following format:

N k
a1 a2 a3 ... a_{N+k}

Here, the first line contains two space-separated integers \(N\) and \(k\). The second line contains exactly \(N+k\) space-separated integers, representing the array.

outputFormat

Output a single integer --- the element which reaches the occurrence count of \(k\) first while scanning the array from left to right.

## sample
5 3
1 2 3 4 5 3 3 3
3