eolymp
bolt
Try our new interface for solving problems
Problems

The following combination

The following combination

Given a set of integers from \textbf{1} to \textbf{n}. Consider a subset of the set consisting of \textbf{k} elements, in ascending order. Print the lexicographically next subset of \textbf{k} elements. \InputFile The first line contains the positive integers \textbf{n} and \textbf{k} (\textbf{1} ≤ \textbf{k} ≤ \textbf{n} ≤ \textbf{50}). The second line contains \textbf{k} integers from \textbf{1} to \textbf{n} in ascending order - a subset of \textbf{k} elements. \OutputFile Print the lexicographicaly next subset of \textbf{k} elements. If there is no such subset, print \textbf{0}.
Time limit 1 second
Memory limit 64 MiB
Input example #1
6 4
1 4 5 6
Output example #1
2 3 4 5