시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB65393664.286%

문제

As Dr. Orooji is getting older, he is becoming more attached to older items and has difficulty letting go of them (he claims they have historical value). For example, he still has the first table he got for the programming team! The situation is the same at home, e.g., there is a broken TV remote control but Dr. O still uses it, because he considers it an old item with historical value!

The old remote control has 12 buttons: digits 0-9, channel down, and channel up. There are no other buttons on the remote control. Some digits on the remote don’t work but channel up/down always works. So, to get to a particular channel, Dr. O sometimes has to use the channel up/down. For example, let’s assume digits 0 and 5 on the remote don’t work:

  • If Dr. O wants to watch channel 102, he would select 99 and then “channel up” 3 times.
  • If he wants to watch channel 597, he would select 611 and then “channel down” 14 times.

Given the digits that do not work and a target channel, determine how many times Dr. O needs to hit channel up or down. Dr. O, of course, wants to exert the least energy, hence he wants to hit the channel up/down the minimum number of times. Assume that Dr. O will enter a channel between 0 and 999 (inclusive) to start and that channel down has no effect at 0 and channel up has no effect at 999.

입력

The first input line contains an integer, n (1 ≤ n ≤ 9), indicating how many digits on the remote do not work. These broken digits are listed (in increasing order) on the same input line. The second input line provides the target channel (an integer between 1 and 999, inclusive).

출력

The output consists of a single integer, indicating how many times Dr. O needs to hit channel up/down. Note that, since one or more digits work, it is always possible to reach the target channel.

예제 입력 1

3 0 8 9
35

예제 출력 1

0

예제 입력 2

4 1 2 5 9
250

예제 출력 2

50