object Main extends App {


  val sc = new java.util.Scanner(System.in)
  var fee, cols = sc.nextInt
  val xss = List.fill(cols)(sc.nextInt)
  var ten: List[Int] = List(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
  var cash = 0
  var count = 0
  var n = 1000
  var flag = false

  for (i <- 0 to 9) {
    if (xss.contains(i)) {
      ten = ten.filter {
        _ != i
      }
    }
  }


  for(i <- fee to 9999){
    if(!flag) {
      if((ten.contains(i / 1000) || fee / 1000 == 0) &&
        (ten.contains(i % 1000 / 100) || (fee / 1000 == 0 && fee % 1000 / 100 == 0)) &&
        (ten. contains(i % 100 / 10) || (fee / 1000 == 0 && fee % 1000 / 100 == 0 && fee % 100 / 10 == 0)) &&
          (ten.contains(i % 10))) {
        flag = true
        cash = i
      }
    }
  }

  print(cash)

}