Problems
First element occurring k times in an array
First element occurring k times in an array
Given an array of n integers. Find the first element that occurs k number of times. If no element occurs k times, print -1.
Input
The first line contains numbers n and k (n, k ≤ 105
). Second line contains n integers, each no more than 109
by absolute value.
Output
Print the first element that occurs k times. If no element occurs k times, print -1.
Input example #1
7 2 1 7 4 3 4 8 7
Output example #1
7
Input example #2
6 1 4 1 6 1 6 4
Output example #2
-1