Problem:
Score : 300 points

Problem Statement

Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K.

She is shopping, and now paying at the cashier.
Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change).

However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.

Find the amount of money that she will hand to the cashier.

Constraints

1 ≦ N < 10000

1 ≦ K < 10

0 ≦ D_1 < D_2 < … < D_K≦9

\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}

Input

The input is given from Standard Input in the following format:

N K
D_1 D_2 … D_K

Output

Print the amount of money that Iroha will hand to the cashier.

Sample Input 1

1000 8
1 3 4 5 6 7 8 9

Sample Output 1

2000

She dislikes all digits except 0 and 2.

The smallest integer equal to or greater than N=1000 whose decimal notation contains only 0 and 2, is 2000.

Sample Input 2

9999 1
0

Sample Output 2

9999

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

//拘り者いろはちゃん//
//イテラブル版
//
using System;
using System.Linq;
using System.Collections.Generic;

namespace tst
{
    class Program
    {
        public static int[] Q = new int[4];//分けられた桁が保管　x=1000なら　Q[3]=1, Q[2]=0,,,
        public static int[] NG = new int[10];
      
        public static void Wake(int x)
        {//桁抽出
            for(int i = 0; i < 4; i++)
            {
                Q[i]=x%10;
                x /= 10;
            }
        }
        public static bool Check()
        {
            for(int i=0; i<Q.Length; i++)
            {
                for(int j=0; j < NG.Length; j++)
                {
                    if (Q[i] == NG[j]) return false;
                }
            }
            return true;
        }
        public static void Main()
        {   //支払金額N円、嫌いな数字K個
            string[] text1 = Console.ReadLine().Split(' ');
            int N = int.Parse(text1[0]);
            int K = int.Parse(text1[1]);
            //嫌いな数字0～9
            string[] D = Console.ReadLine().Split(' ');
            NG = D.Select(s => int.Parse(s)).ToArray();
            //逆に使える数の配列
            List<string> All = new List<string>() { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
            for (int i = 0; i < K; i++)
            {
                All.Remove(D[i]);
            }
            int[] Ok = new int[10 - K];
            for (int i = 0; i <Ok.Length; i++)
            {
                Ok[i] = int.Parse(All[i]);
            }
            bool flag = false;
            for(int i=N; i<10000; i++)
            {
                Wake(i);//Q[0],,Q[3]
                if (Check())
                {
                    flag = true;
                    Console.WriteLine(i);
                    break;
                }
                else
                {
                    continue;
                }
                
            }
            if (!flag)//4桁で成功しなかったら
            {
                //４ケタで支払えず、minが初期値のままだった場合//５ケタの最小の数を返す
                if (Ok[0] == 0)
                {
                    Console.WriteLine(Ok[1] * 10000);
                }
                else if (1 <= Ok[0] && Ok[0] <= 9)
                {
                    Console.WriteLine(Ok[0] * 10000 + Ok[0] * 1000 + Ok[0] * 100 + Ok[0] * 10 + Ok[0]);
                }
            }
            
        }

    }
}