cho.sh
Notes
Loading...

Remote Control

Time limit

2s

Memory limit

256 MB

Problem

Subin is watching TV. Some numeric buttons on the remote control are broken, so it may be impossible to enter every desired channel number directly.

The remote has numeric buttons from 0 through 9 and the + and - buttons. Pressing + moves to the channel that is 1 higher than the current channel, and pressing - moves to the channel that is 1 lower. If - is pressed on channel 0, the channel stays at 0. There is no upper limit on channel numbers.

The current channel is 100. Given the list of broken numeric buttons, find the minimum number of button presses needed to move to the target channel N.

Input

The first line contains the target channel N. (0 <= N <= 500,000)

The second line contains the number M of broken numeric buttons. (0 <= M <= 10)

If M is at least 1, the third line contains the M broken numeric buttons separated by spaces. The same button is not listed more than once.

Output

Print one line containing the minimum number of button presses needed to move to channel N.

Hint

Using only + or - from channel 100 is also a candidate answer. Also compare it with entering some channel using only working numeric buttons first, then correcting to the target with + or -.