Under construction

Still being built. Things may change

Jumping on Stones

Interview

Time limit2sMemory limit1024 MB

Summary
Find the fewest 1 or 2 meter jumps from point 0 to point n that land only on stones, and print the lexicographically smallest jump sequence.
Level

Medium5 of 10

Topics
Dynamic programming, Array, String
Solved
No attempts yet

Problem

Judy Hopps is running to a very important meeting with Nick, and suddenly a huge lake blocks her way. She has no time to go around it, so she needs another plan. Luckily, a few stones poke out of the lake's surface, and she can jump on them.

Treat the lake as a coordinate line. Judy stands at point 0, and the far end of the lake is at point nn. Judy is a rabbit and good at jumping, but she can only jump 1 or 2 meters forward (that is, from point xx she can reach x+1x+1 or x+2x+2). Given the coordinates of the stones, find the minimum number of jumps needed to get from point 0 to point nn. Judy also wants to do this as optimally as possible, so among all paths with the minimum number of jumps, she wants the lexicographically smallest one. Each jump is written as a number 1 or 2, where the ii-th number is the length of the ii-th jump.

Help Judy solve this quickly. Even though she is a lady, being very late to the meeting is rude.

Input

The first line contains two integers nn and kk (1≤n≤1051 \le n \le 10^5; 0≤k<n0 \le k < n), the coordinate Judy needs to reach and the number of stones in the lake. The second line contains kk integers xix_i separated by spaces (1≤xi≤n1 \le x_i \le n), the coordinates of the stones. It is guaranteed that x1>0x_1 > 0, and for every i>1i > 1, xi>xi−1x_i > x_{i-1}.

Output

The first line contains the minimum number of jumps needed to get from coordinate 0 to coordinate nn. The second line contains the optimal path, a sequence of 1s and 2s without spaces. The path must have minimum length, and among all such paths it must be lexicographically smallest. If Judy cannot reach point nn without going around the lake, print -1 on a single line.

Hint

A sequence AA is lexicographically smaller than a sequence BB if A≠BA \ne B and there is some 0≤k≤∣A∣0 \le k \le |A| such that A0=B0,A1=B1,…,Ak=BkA_0 = B_0, A_1 = B_1, \ldots, A_k = B_k and Ak+1<Bk+1A_{k+1} < B_{k+1}.

Examples2

  1. Example 1

    Input
    5 3
    2 3 4
    
    Expected output
    3
    212
    
  2. Example 2

    Input
    7 3
    2 3 4
    
    Expected output
    -1