const reader = require('fs')
main(reader.readFileSync('/dev/stdin', 'utf8'))


function main(arg) {
  const data = arg.trim().split("\n")
  const N = Number(data[0].split(" ")[0])
  const invalid = data[1].split(' ')
  console.log(solve(N, invalid))
}

function solve(N, invalid) {
  const list = N.toString().split('')
  if (list.every(n => invalid.indexOf(n) === -1)) {
    return N
  } else {
    return solve(N+1, invalid)
  }
}


