let n = 
	let str = read_line () in
	Scanf.sscanf str "%d" (fun n -> n)

let digits =
	read_line ()
	|> Str.split (Str.regexp " ") 
	|> List.map int_of_string

let payment =
	let rec hasBadDigit n =
		if n <= 9 then
			List.exists (fun x -> x = n) digits
		else if List.exists (fun x -> x = n mod 10) digits then
			true
		else 
			hasBadDigit (n / 10)
	in
	let rec loop n =
		if hasBadDigit n then loop (n + 1)
		else n
	in
	loop n

let () =
	Printf.printf "%d\n" payment
