#K61057. Smallest Missing Positive Integer

    ID: 31224 Type: Default 1000ms 256MiB

Smallest Missing Positive Integer

Smallest Missing Positive Integer

You are given an array of integers that may include positive numbers, zeros, and negative numbers. Your task is to find the smallest positive integer \( m \) such that \( m \) does not appear in the array.

In other words, let \( A \) be the set of integers given. Find the smallest \( m \in \mathbb{Z^+} \) (i.e., \( m \geq 1 \)) for which \( m \notin A \).

Note: The array may be empty. In that case, the answer is 1.

inputFormat

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

  • The first line contains an integer \( n \), representing the number of elements in the array.
  • The second line contains \( n \) space-separated integers representing the array elements. If \( n = 0 \), this line may be omitted.

outputFormat

Output a single integer: the smallest positive integer that is not present in the array. The output should be printed to standard output (stdout).

## sample
5
1 2 0 4 5
3