local n, k = io.read("*n", "*n")
local t = {}
for i = 1, k do
  local z = io.read("*n")
  t[z] = true
end
while true do
  local len = #(tostring(n))
  local valid = true
  local v = n
  for i = 1, len do
    local tmp = v % 10
    if t[tmp] then valid = false break end
    v = v // 10
  end
  if valid then print(n) break end
  n = n + 1
end
