SDE Path

Search Insert Position

Easy

Search Insert Position

Given a sorted array and a target, return the index where the target would be inserted to keep it sorted.

Input format

The first line contains N and the target. The second line contains N distinct integers in sorted order.

Output format

Print the index of the target if present, otherwise the index where it would be inserted to keep the array sorted.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
4 5
1 3 5 6
Expected output
2
Example 2
Input
4 2
1 3 5 6
Expected output
1