#K70952. Nth Smallest Unique Number Index

    ID: 33422 Type: Default 1000ms 256MiB

Nth Smallest Unique Number Index

Nth Smallest Unique Number Index

You are given a list of M integers and an integer N. Your task is to find the Nth smallest unique number in the list and return the 0-indexed position of its first occurrence. If the Nth smallest unique number does not exist, output -1.

A unique number is defined as a distinct integer occurring in the list. The Nth smallest unique number is the number that occupies the Nth position when all unique numbers are sorted in strictly increasing order.

Input Constraints:

  • 1 ≤ M ≤ 105
  • 1 ≤ N ≤ M

Input Format:

  • The first line contains two integers M and N separated by a space.
  • The second line contains M space-separated integers.

Output Format:

  • Output a single integer representing the index of the Nth smallest unique number in the list, or -1 if it does not exist.

Example:

Input:
7 3
4 5 1 2 2 1 3

Output: 6

inputFormat

The input is read from stdin and consists of two lines:

  • The first line contains two integers M and N, where M is the number of elements and N represents the desired order statistic.
  • The second line contains M space-separated integers.

outputFormat

Output a single integer on stdout which is the index (0-indexed) of the Nth smallest unique number. If the Nth unique number does not exist, output -1.

## sample
7 3
4 5 1 2 2 1 3
6