#C7172. Smallest Missing Positive Integer

    ID: 51014 Type: Default 1000ms 256MiB

Smallest Missing Positive Integer

Smallest Missing Positive Integer

Given an array of integers, your task is to find the smallest positive integer that is missing from the array. The input begins with an integer n which represents the number of elements in the array, followed by n space-separated integers. The answer is the smallest natural number (i.e. a number greater than 0) that does not appear in the array.

Example:

Input:
6
1 3 6 4 1 2

Output: 5

</p>

The problem can be formalized as: Find the smallest positive integer m such that m \notin A, where A is the set of positive integers present in the array.

inputFormat

The input is given from stdin and has the following format:

  • The first line contains an integer n (0 ≤ n ≤ 105), the number of elements in the array.
  • If n > 0, the second line contains n space-separated integers.

If n is 0, then the array is empty.

outputFormat

Output a single integer to stdout representing the smallest missing positive integer.

## sample
6
1 3 6 4 1 2
5