integer N,K
character,allocatable,dimension(:)::a
read*,N,K
allocate(a(k))
read*,a

do
  if(check(N,a))exit
  N=N+1
end do

print"(i0)",N

contains
pure function check(N,a)
  integer,intent(in)::N
  character,intent(in)::a(:)
  character(6)B
  logical check
  check=.TRUE.
  write(B,"(i0)")N
  do i=1,size(a)
    if(index(B,a(i))/=0)check=.false.
  end do
end function check
end