Algorithms and Data Structures

• Status
• 1
Implementation
• 2
Bitwise operations
• 3
Prefix Sums
• 4
Sliding window / Two pointers
• 5
Modular Arithmetic
• 6
Number Theory
• 7
Binary Search
• 8
Basic Sorting
• 9
Greedy Algorithms
• 10
Basic Dynamic Programming
• 11
Recursion
• 12
• 13
Queue & Stack
• 14
Binary tree + BST
• 15
Divide & Conquer + Advanced Sorting
• 16
Heap
• 17
Hashing
• 18
Graph Representation
• 19
BFS

• # Minimum Excluded value (MEX)

Let’s consider the positive whole numbers (0, 1, 2, …). For a given list of numbers `l`, we’ll say that the minimum excluded value (MEX) of `l` is the smallest nonnegative integer number that doesn’t occur in `l`. You are asked to write a program that given the list `l`, would calculate its MEX.

#### Input

The first line of the input contains a single integer `n` (1 ≤ n ≤ ) the number of elements in the list `l`. The next line contains `n` elements representing the list .

#### Output

The program should print the MEX of the given list.

#### Examples

 Input Output 3 1 2 3 0 4 0 1 3 4 2 5 0 1 2 3 4 5

#### Constraints

Time limit: 1 seconds

Memory limit: 512 MB

Output limit: 1 MB