시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 256 MB 40 8 7 43.750%

문제

준규는 칠판에 N으로 시작하는 연속하는 양의 정수 K개를 칠판에 써놓았다. 준규가 잠시 화장실에 간 사이에 해빈이는 각각의 숫자에서 한 자리를 제외한 나머지 자리를 모두 지워놓았다. 

해빈이가 지워서 생긴 새로운 수열이 주어졌을 때, 원래 준규가 적은 수열을 구하는 프로그램을 작성하시오.

입력

첫째 줄에 수열의 길이 K(1 ≤ K ≤ 100,000)가 주어진다. 둘째 줄에는 해빈이가 지워서 만든 수열을 나타내는 K개의 정수 B1, B2, ..., BK가 주어진다. (0 ≤ Bi ≤ 9)

출력

첫째 줄에 가능한 준규 수열 중 N이 가장 작은 것의 N을 출력한다.

예제 입력 1

6
7 8 9 5 1 2

예제 출력 1

47

힌트

준규가 칠판에 적은 수열은 47 48 49 50 51 52이고, N이 47보다 작으면서 가능한 수열은 없다.

W3sicHJvYmxlbV9pZCI6IjEwMDk3IiwicHJvYmxlbV9sYW5nIjoiMCIsInRpdGxlIjoiXHVjMjE4XHVjNWY0IiwiZGVzY3JpcHRpb24iOiI8cD5cdWM5MDBcdWFkZGNcdWIyOTQgXHVjZTYwXHVkMzEwXHVjNWQwIE5cdWM3M2NcdWI4NWMgXHVjMmRjXHVjNzkxXHVkNTU4XHViMjk0IFx1YzVmMFx1YzE4ZFx1ZDU1OFx1YjI5NCBcdWM1OTFcdWM3NTggXHVjODE1XHVjMjE4IEtcdWFjMWNcdWI5N2MgXHVjZTYwXHVkMzEwXHVjNWQwIFx1YzM2OFx1YjE5M1x1YzU1OFx1YjJlNC4gXHVjOTAwXHVhZGRjXHVhYzAwIFx1YzdhMFx1YzJkYyBcdWQ2NTRcdWM3YTVcdWMyZTRcdWM1ZDAgXHVhYzA0IFx1YzBhY1x1Yzc3NFx1YzVkMCBcdWQ1NzRcdWJlNDhcdWM3NzRcdWIyOTQgXHVhYzAxXHVhYzAxXHVjNzU4IFx1YzIyYlx1Yzc5M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