object Main extends App {


  val sc = new java.util.Scanner(System.in)
  val 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 = 10000
  var flag = true

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

  for (j <- 0 until 3) {
    n /= 10
    flag = true
    for (i <- 0 to 9) {
      if (ten.contains(fee / n + i) && flag) {
        cash += (fee / n + i) * n
        flag = false
      }
    }
  }

  print(cash)

}