All problems

Problem 784

Linear Search

Easy · 10 pts · Array, Basics, Searching

Problem

Find the first position (counting from 0) where the value X appears in the array, or print -1 if it does not appear. Linear search checks the elements one by one from the start and stops at the first match. It works on any array, sorted or not, and takes at most N comparisons.

Input

The first line contains N and X. The second line contains the N array elements.

Output

Print the index of the first occurrence of X, or -1.

Constraints

1 <= N <= 100000; -10^9 <= A[i], X <= 10^9

Example input

4 8
4 8 15 8

Example output

1

Explanation

In 4 8 15 8 with X = 8, the first 8 is at index 1 (the second element), so the answer is 1.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Count Occurrences of a Value Next: Sum of Elements at Even Indices