import java.util.regex.Pattern

import scala.io.StdIn

object Solution {
  //Console.setIn(new FileReader(new java.io.File("in")))
  //Console.setOut(new PrintStream(new java.io.File("output")))

  val magicMod = 1000000007

  def doCase(caseNo: Int): Unit = {
    val str = readLine()

    var state = 0
    var i = 0
    while (i < str.length) {
        if (state == 0 && str(i) == '[') {
          state += 1
        } else if (state == 1 && str(i) == ':') {
          state += 1
        } else if (state == 2 && str(i) == ':') {
          state += 1
        } else if (state == 3 && str(i) == ']') {
        state += 1
        }
      i += 1
    }

    if (state != 4) {
      println(-1)
      return
    }

    var firstLBracket : Option[Int] = None
    var lastRBracket : Option[Int] = None

    i = 0
    while (i < str.length) {
      if (str(i) == '[') {
        firstLBracket = firstLBracket.orElse(Some(i))
      } else if (str(i) == ']') {
        lastRBracket = Some(i)
      }
      i += 1
    }

    if (firstLBracket.isEmpty || lastRBracket.isEmpty || firstLBracket.get > lastRBracket.get) {
      println(-1)
      return
    }

    var barCount = 0
    val cumulativeBars = Array.fill(str.length + 1)(0)

    i = 0
    while (i <= str.length) {
      cumulativeBars(i) = barCount
      if (i < str.length && str(i) == '|') {
        barCount += 1
      }
      i += 1
    }

    var colons : List[Int] = List()
    i = firstLBracket.get
    while (i < lastRBracket.get) {
      if (str(i) == ':') {
        colons ::= i
      }
      i += 1
    }
    colons = colons.reverse

    var bestCount = 0

    val l = colons.head
    val r = colons.last
    val count = cumulativeBars(r) - cumulativeBars(l)
    bestCount = if (bestCount < count) count else bestCount

    println(bestCount + 4)
  }

  def main(args: Array[String]): Unit = {
    val noCases = 1
    for (i <- 0 until noCases) {
      doCase(i)
    }
  }

  def readIntLine(): Array[Int] = {
    StdIn.readLine().split(" ").map(_.toInt)
  }

  def readLongLine(): Array[Long] = {
    StdIn.readLine().split(" ").map(_.toLong)
  }

  def readBigIntLine(): Array[BigInt] = {
    StdIn.readLine().split(" ").map(BigInt.apply)
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val S = ns()
    val open = S.indexWhere(_ == '[')
    val close = S.lastIndexWhere(_ == ']')

    if (open != -1 && close != -1) {
      val first = S.indexWhere(_ == ':', open + 1)
      val last = S.lastIndexWhere(_ == ':', close - 1)
      if (first != -1 && last != -1 && open < first && first < last && last < close) {
        val ans = S.slice(first + 1, last).count(_ == '|') + 4
        out.println(ans)
      } else {
        out.println(-1)
      }
    } else {
      out.println(-1)
    }
  }

  def debug(as: Array[Boolean]): Unit = {
    System.err.println(as.map(x => if(x) "1" else "0").mkString)
  }

  def debug(as: Array[Int]): Unit = {
    System.err.println(as.mkString(" "))
  }

  def debug(as: Array[Long]): Unit = {
    System.err.println(as.mkString(" "))
  }

  def debug(s: String): Unit = {
    System.err.println(s)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

object EDU_58_B {

  type In = (String)
  type Out = Int

  def solve(in: In): Out = {
    val (s) = in

    def eat(s: String, c: Char): Option[String] =
      s.indexOf(c) match {
        case -1 => None
        case i  => Some(s.substring(i + 1))
      }

    val lines = for {
      p1 <- eat(s, '[')
      p2 <- eat(p1, ':')
      r = p2.reverse
      p4 <- eat(r, ']')
      p3 <- eat(p4, ':')
    } yield p3.count(_ == '|')

    lines match {
      case None => -1
      case Some(i) => i + 4
    }
  }

//   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//   Specify Input and Output formats on RHS here:

  def formatIn(i: Input): In       = (i.nextLine)
  def formatOut(out: Out): String  = out.toString

//   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//   Boilerplate & utility methods that don't change:

  import java.io.InputStream
  import java.util.Scanner

  import language.implicitConversions

  def main(args: Array[String]): Unit = {
    val out = new java.io.PrintWriter(System.out)
    val resultStr = new Input(System.in).solveStr
    out.println(resultStr)
    out.close()
  }

  class Input(sc: Scanner) {
    // This class is useful for convenience, and for mock stdin in test scripts
    // Remember to call nextLine to advance past the newline character (if required) before taking a whole line
    def this(i: InputStream) =       this(new Scanner(i))
    def this(s: String) =            this(new Scanner(s.stripMargin))
    def int =                        sc.nextInt()
    def long =                       sc.nextLong()
    def double =                     sc.nextDouble()
    def nextLine =                   sc.nextLine()
    def collect[T](f: String => T) = sc.nextLine().split(" ").toVector.map(f)
    def intSeq =                     collect(_.toInt)
    def doubleSeq =                  collect(_.toDouble)
    def getLines: Vector[String] =   if (!sc.hasNextLine) Vector.empty
                                     else sc.nextLine +: getLines
    def solveVal: Out =              (solve _).tupled(formatIn(this))
    def solveStr: String =           formatOut(solveVal)
  }

  // Ceiling division for Int & Long
  def ceil(a: Int, b: Int)   = (a - 1)/b + 1
  def ceil(a: Long, b: Long) = (a - 1)/b + 1

  // A frequently used number
  val modulo = 1000000007

  // For convenience in test scripts, treat a String as an Input
  implicit def stringToInput(s: String): Input = new Input(s)
  // Required to make `solveVal` work when input has just 1 value (i.e. not a Tuple)
  implicit class makeTupledWorkOnFunction1[-T,+R](f: T => R) {
    def tupled: T => R = x => f(x)
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val S = ns()
    val open = S.indexWhere(_ == '[')
    val first = S.indexWhere(_ == ':')
    val last = S.lastIndexWhere(_ == ':')
    val close = S.lastIndexWhere(_ == ']')
    val found = open != -1 && first != -1 && last != -1 && close != -1
    if (found && open < first && first < last && last < close) {
      val ans = S.slice(first + 1, last).count(_ == '|') + 4
      out.println(ans)
    } else {
      out.println(-1)
    }
  }

  def debug(as: Array[Boolean]): Unit = {
    System.err.println(as.map(x => if(x) "1" else "0").mkString)
  }

  def debug(as: Array[Int]): Unit = {
    System.err.println(as.mkString(" "))
  }

  def debug(as: Array[Long]): Unit = {
    System.err.println(as.mkString(" "))
  }

  def debug(s: String): Unit = {
    System.err.println(s)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val S = ns()
    val open = S.indexWhere(_ == '[')
    val first = S.indexWhere(_ == ':')
    val last = S.lastIndexWhere(_ == ':')
    val close = S.lastIndexWhere(_ == ']')
    if (open < first && first < last && last < close) {
      val ans = S.slice(first + 1, last).count(_ == '|') + 4
      out.println(ans)
    } else {
      out.println(-1)
    }
  }

  def debug(as: Array[Boolean]): Unit = {
    System.err.println(as.map(x => if(x) "1" else "0").mkString)
  }

  def debug(as: Array[Int]): Unit = {
    System.err.println(as.mkString(" "))
  }

  def debug(as: Array[Long]): Unit = {
    System.err.println(as.mkString(" "))
  }

  def debug(s: String): Unit = {
    System.err.println(s)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

object EDU_58_B {

  type In = (String)
  type Out = Int

  def solve(in: In): Out = {
    val (s) = in

    val model = "[::]"

    val ans = {
      def loop(in: Seq[Char], out: String, nextChars: String, colonCount: Int): String = in match {
        case Seq() => out
        case _ if nextChars.isEmpty => out
        case _ => in.head match {
          case h if h == nextChars.head             => loop(in.tail, out + h, nextChars.tail, colonCount)
          case h if h == nextChars.head && h == ':' => loop(in.tail, out + h, nextChars.tail, colonCount + 1)
          case h if h == '|' && colonCount == 1     => loop(in.tail, out + h, nextChars, colonCount)
          case _                                    => loop(in.tail, out, nextChars, colonCount)
        }
      }
      loop(s, "", model, 0)
    }

    /*s.foldLeft("") { (acc, c) =>
      (acc, c) match {
        case ("", '[') => "["
        case ("[", ':') => "[:"
        case (_, '|') if acc.matches("""^\[\:\|*""") => acc + '|'
        case (_, ':') if acc.matches("""^\[\:\|*""") => acc + ':'
        case (_, ']') if acc.matches("""^\[\:\|*\:""") => acc + ']'
        case _ => acc
      }
    }*/

    if(ans.matches("""^\[\:\|*\:\]$""")) ans.length else -1

  }

//   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//   Specify Input and Output formats on RHS here:

  def formatIn(i: Input): In       = (i.nextLine)
  def formatOut(out: Out): String  = out.toString

//   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//   Boilerplate & utility methods that don't change:

  import java.io.InputStream
  import java.util.Scanner

  import language.implicitConversions

  def main(args: Array[String]): Unit = {
    val out = new java.io.PrintWriter(System.out)
    val resultStr = new Input(System.in).solveStr
    out.println(resultStr)
    out.close()
  }

  class Input(sc: Scanner) {
    // This class is useful for convenience, and for mock stdin in test scripts
    // Remember to call nextLine to advance past the newline character (if required) before taking a whole line
    def this(i: InputStream) =       this(new Scanner(i))
    def this(s: String) =            this(new Scanner(s.stripMargin))
    def int =                        sc.nextInt()
    def long =                       sc.nextLong()
    def double =                     sc.nextDouble()
    def nextLine =                   sc.nextLine()
    def collect[T](f: String => T) = sc.nextLine().split(" ").toVector.map(f)
    def intSeq =                     collect(_.toInt)
    def doubleSeq =                  collect(_.toDouble)
    def getLines: Vector[String] =   if (!sc.hasNextLine) Vector.empty
                                     else sc.nextLine +: getLines
    def solveVal: Out =              (solve _).tupled(formatIn(this))
    def solveStr: String =           formatOut(solveVal)
  }

  // Ceiling division for Int & Long
  def ceil(a: Int, b: Int)   = (a - 1)/b + 1
  def ceil(a: Long, b: Long) = (a - 1)/b + 1

  // A frequently used number
  val modulo = 1000000007

  // For convenience in test scripts, treat a String as an Input
  implicit def stringToInput(s: String): Input = new Input(s)
  // Required to make `solveVal` work when input has just 1 value (i.e. not a Tuple)
  implicit class makeTupledWorkOnFunction1[-T,+R](f: T => R) {
    def tupled: T => R = x => f(x)
  }
}

object EDU_58_B {

  type In = (String)
  type Out = Int

  def solve(in: In): Out = {
    val (s) = in

    val Reg = """^\[\:\|*\:\]$"""
    def isAccordian(s: String) = s matches Reg

    val a = "[::]"

    val p1 = s.dropWhile(_ != '[')

    val ans = s.foldLeft("") { (acc, c) =>
      (acc, c) match {
        case ("", '[') => "["
        case ("[", ':') => "[:"
        case (_, '|') if acc.matches("""^\[\:\|*""") => acc + '|'
        case (_, ':') if acc.matches("""^\[\:\|*""") => acc + ':'
        case (_, ']') if acc.matches("""^\[\:\|*\:""") => acc + ']'
        case _ => acc
      }
    }

    if(ans.matches(Reg)) ans.length else -1

  }

//   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//   Specify Input and Output formats on RHS here:

  def formatIn(i: Input): In       = (i.nextLine)
  def formatOut(out: Out): String  = out.toString

//   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//   Boilerplate & utility methods that don't change:

  import java.io.InputStream
  import java.util.Scanner

  import language.implicitConversions

  def main(args: Array[String]): Unit = {
    val out = new java.io.PrintWriter(System.out)
    val resultStr = new Input(System.in).solveStr
    out.println(resultStr)
    out.close()
  }

  class Input(sc: Scanner) {
    // This class is useful for convenience, and for mock stdin in test scripts
    // Remember to call nextLine to advance past the newline character (if required) before taking a whole line
    def this(i: InputStream) =       this(new Scanner(i))
    def this(s: String) =            this(new Scanner(s.stripMargin))
    def int =                        sc.nextInt()
    def long =                       sc.nextLong()
    def double =                     sc.nextDouble()
    def nextLine =                   sc.nextLine()
    def collect[T](f: String => T) = sc.nextLine().split(" ").toVector.map(f)
    def intSeq =                     collect(_.toInt)
    def doubleSeq =                  collect(_.toDouble)
    def getLines: Vector[String] =   if (!sc.hasNextLine) Vector.empty
                                     else sc.nextLine +: getLines
    def solveVal: Out =              (solve _).tupled(formatIn(this))
    def solveStr: String =           formatOut(solveVal)
  }

  // Ceiling division for Int & Long
  def ceil(a: Int, b: Int)   = (a - 1)/b + 1
  def ceil(a: Long, b: Long) = (a - 1)/b + 1

  // A frequently used number
  val modulo = 1000000007

  // For convenience in test scripts, treat a String as an Input
  implicit def stringToInput(s: String): Input = new Input(s)
  // Required to make `solveVal` work when input has just 1 value (i.e. not a Tuple)
  implicit class makeTupledWorkOnFunction1[-T,+R](f: T => R) {
    def tupled: T => R = x => f(x)
  }
}

import java.util.regex.Pattern

import scala.io.StdIn

object Solution {
  //Console.setIn(new FileReader(new java.io.File("in")))
  //Console.setOut(new PrintStream(new java.io.File("output")))

  val magicMod = 1000000007

  def doCase(caseNo: Int): Unit = {
    val str = readLine()

    if (!Pattern.matches(".*\\[.*:.*:.*\\].*", str)) {
      println(-1)
      return
    }

    var firstLBracket : Option[Int] = None
    var lastRBracket : Option[Int] = None

    var i = 0
    while (i < str.length) {
      if (str(i) == '[') {
        firstLBracket = firstLBracket.orElse(Some(i))
      } else if (str(i) == ']') {
        lastRBracket = Some(i)
      }
      i += 1
    }

    if (firstLBracket.isEmpty || lastRBracket.isEmpty || firstLBracket.get > lastRBracket.get) {
      println(-1)
      return
    }

    var barCount = 0
    val cumulativeBars = Array.fill(str.length + 1)(0)

    i = 0
    while (i <= str.length) {
      cumulativeBars(i) = barCount
      if (i < str.length && str(i) == '|') {
        barCount += 1
      }
      i += 1
    }

    var colons : List[Int] = List()
    i = firstLBracket.get
    while (i < lastRBracket.get) {
      if (str(i) == ':') {
        colons ::= i
      }
      i += 1
    }
    colons = colons.reverse

    var bestCount = 0
    for (List(l, r) <- colons.sliding(2)) {
      val count = cumulativeBars(r) - cumulativeBars(l)
      bestCount = if (bestCount < count) count else bestCount
    }

    println(bestCount + 4)
  }

  def main(args: Array[String]): Unit = {
    val noCases = 1
    for (i <- 0 until noCases) {
      doCase(i)
    }
  }

  def readIntLine(): Array[Int] = {
    StdIn.readLine().split(" ").map(_.toInt)
  }

  def readLongLine(): Array[Long] = {
    StdIn.readLine().split(" ").map(_.toLong)
  }

  def readBigIntLine(): Array[BigInt] = {
    StdIn.readLine().split(" ").map(BigInt.apply)
  }
}


import java.util.StringTokenizer
import java.io.BufferedReader
import java.io.BufferedInputStream
import java.io.InputStreamReader
import java.io.ByteArrayInputStream
import java.io.InputStream
import java.security.SecureRandom

object CF_504_D {   var br = createBufferedReader(); var debugV = false

    //COMMENT ME !
    runTest(Test.t7)
//    debugV = true
//    runFromFile("""C:\work\git\ap-codeforces\Codeforces\src\fb\aprokh\fb2018r2\jacks_candy_shop_2.txt""")

  def main(args: Array[String]): Unit = {
    //---------------------------- parameters reading
    val l1 = readLine
    val n = l1.int
    val Q = l1.int
    val arrLine = readLine
    val arr = new Array[Int](n)
    val startTime = System.currentTimeMillis()

    class Cell(val ind: Int, val value: Int) {
      var prev: Cell = null
      var next: Cell = null
    }

    class ArrList() {
      var first: Cell = null
      var last: Cell = null

      def add(cc: Cell) {
        if (first == null) {
          first = cc
        } else {
          last.next = cc
          cc.prev = last
        }
        last = cc
      }
      def remove(cc: Cell) {
        if (cc.prev != null) {
            cc.prev.next = cc.next
        }
        if (cc.next != null) {
          cc.next.prev = cc.prev
        }
        if (cc == first) {
          first = cc.next
        }
        if (cc == last) {
          last = cc.prev
        }
      }
      def mkString: String= {
        var cur = first
        var res = ""
        while (cur != null) {
//          res += cur.ind+"-"+cur.value + ","
          res += cur.value + ","
          cur = cur.next
        }
        res
      }
    }
    val aList = new ArrList()

    for(i <- 0 until n) {
      val vv = arrLine.int
      arr(i) = vv
    }

    var cur = aList.first
    while (cur != null) {
      print(cur.value + " ")
      cur = cur.next
    }
    println

//    if (arr(0) == 1912) {
//      var acc = ""
//      for(i <- 0 until n) {
//        acc += arr(i) + " "
//        if (i % 50 == 0) {
//          println(acc)
//          acc = ""
//        }
//      }
//    }

    var lastPresent = false
    var zeroInd = -1
    for( i <- 0 until n) {
      if (arr(i) == Q) lastPresent = true
      if (arr(i) == 0) zeroInd = i
    }
    if (!lastPresent && zeroInd != -1) arr(zeroInd) = Q

    //copy to linked list
    val starts = new Array[Cell](Q+1)
    val counts = new Array[Int](Q+1)
    for(i <- 0 until n) {
      val q = arr(i)
      val cc = new Cell(i, q)
      if (starts(q) == null) { starts(q) = cc }
      counts(q) += 1
      aList.add(cc)
    }

    val resArr = new Array[Int](n)
    var good = true

//    def calc(): Unit = {
//      for(qu <- Q to 1 by -1) {
//        var started = false
//        var finished = false
//        for(i <- 0 until n) {
//          (started, finished) match {
//            case (false, false) => {
//              if (arr(i) == qu) {
//                started = true
//                arr(i) = -1
//                resArr(i) = qu
//              }
//            }
//            case (true, false) => {
//              if (arr(i) != qu && arr(i) != 0 && arr(i) != -1) {
//                finished = true
//              } else { //still continue
//                if (arr(i) != -1) {
//                  resArr(i) = qu
//                  arr(i) = -1
//                }
//              }
//            }
//            case (true, true) => {
//              if (arr(i) == qu) {
//                good = false
//  //              if (arr(0) == 1912) {
//  //                println("Break on " + qu + " i=" + i)
//  //              }
//              }
//            }
//          }
//          if (!good) return
//        }
////        debug("After: " + qu)
//      }
//    }
//    calc()

    debug("After query " + "0" + ": " + aList.mkString)

    val sss = System.currentTimeMillis()
    var totalSteps = 0
    def calc2(): Unit = {
      for(qu <- Q to 1 by -1) {
        var started = false
        var finished = false
        var curCell = starts(qu)
        while(good && curCell != null && counts(qu) > 0) {
          totalSteps += 1
          (started, finished) match {
            case (false, false) => {
              if (curCell.value == qu) {
                started = true
                aList.remove(curCell)
                resArr(curCell.ind) = qu
                counts(qu) -= 1
//                debug("Removed first cell" + curCell)
              }
            }
            case (true, false) => {
              if (curCell.value != qu && curCell.value != 0) {
                finished = true
//                debug("finished")
              } else { //still continue
                aList.remove(curCell)
                resArr(curCell.ind) = qu
                if (curCell.value == qu) { counts(qu) -= 1 }
//                debug("Removed subseq cell" + curCell)
              }
            }
            case (true, true) => {
              if (curCell.value == qu) {
                debug("Fail at secondary piece: " + qu)
                good = false
              }
            }
          }
//          debug(" - After step " + qu + ": " + aList.mkString)
          curCell = curCell.next
        }
        debug("After query " + qu + ": " + aList.mkString)
      }
    }
    calc2
    val ddd = System.currentTimeMillis() - sss
    debug("calc2 dur " + ddd + "  steps=" + totalSteps)

    var last = resArr(n-1)
//    if (last == 0) last = Q
    for(i <- n-1 to 0 by -1) {
      if (resArr(i) == 0) {
        resArr(i) = last
      }
      last = resArr(i)
    }
    last = resArr(0)
    for(i <- 0 until n) {
       if (resArr(i) == 0) {
        resArr(i) = last
      }
      last = resArr(i)
    }

    lastPresent = false
    for( i <- 0 until n) {
      if (resArr(i) == Q) lastPresent = true
    }
    if (!lastPresent) {
      debug("Fail at top query absent")
      good = false
    }

    if (good) {
      outLn("YES")
      outLn(resArr.mkString(" "))
    } else {
      outLn("NO")
    }

    debug("================= RESULT ================== ")
    val endTime = System.currentTimeMillis() - startTime
    debug("Exec time: " + endTime)
    finish
  }

  //============================ service code ======================

//  var file:File = null
  val resultStr = new StringBuilder
  def outLn(str:String) = resultStr.append(str).append("\n")
  def outLn(number:Integer) = resultStr.append(number+"").append("\n")
  def finish() {
//    if (file == null || !devEnv) {
      println(resultStr.toString())
      Console.flush()
//    } else {
//      file.writeAll(resultStr.toString())
//    }
  }

  def readLine() = new Line
  class Line {
    val fullLine = br.readLine()
    val tok = new StringTokenizer(fullLine, " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()
  }

  def createBufferedReader(inst:InputStream = System.in): BufferedReader = {
    val bis = if (inst == null) new BufferedInputStream(System.in) else new BufferedInputStream(inst);
    new BufferedReader(new InputStreamReader(bis));
  }

  def runTest(str:String) = if (devEnv) {
    br = createBufferedReader(new ByteArrayInputStream(str.trim.getBytes("ISO-8859-1")))
  }

//  def runFromFile(fileName: String) = if (devEnv) {
//    br = createBufferedReader(new FileInputStream(fileName))
//  }

  def debug(x: => String) = if (debugV && devEnv) println(x) // nullary function

  lazy val devEnv = this.getClass.getCanonicalName.contains(".")

//============================================================================================
object Test {

val sa1 = """
4 3
1 0 2 3
"""

val sa2 = """
"""

val t7 = """
50 2
0 1 0 1 0 0 1 0 1 1 0 1 1 1 2 2 0 2 0 2 0 2 0 0 2 2 2 0 0 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 1 0 1 0 0
"""

val m1 = """
4 3
1 0 2 3
"""

val m2 = """
20 20
17 17 19 19 17 20 20 17 16 16 16 16 16 18 18 18 18 18 6 0
"""

def gen = {
  val runStart = System.currentTimeMillis()
  val n = 200000
  val q = 200000
  val rr = new SecureRandom
  val arr = new Array[Int](n)
  for(i <- 1 to q) {
    val start = rr.nextInt(n-1)
    val length = 1 //rr.nextInt(n-start-1)
//    val length = n-q
    val end = length + start
    for (j <- start to end) {
      arr(j) = i
    }
  }
  val res = s"$n $q" + "\n" + arr.mkString(" ")
  val runEnd = System.currentTimeMillis() - runStart
  println("Gen time " + runEnd)
  println(res)
  res
}

}

}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N, Q = ni()
    val A = na(N)

    val seg = new SegmentTree(N)
    rep(N) { i =>
      val a = A(i)
      if (a != 0) seg.update(i, a)
    }

    val L = Array.fill[Int](Q + 1)(-1)
    val R = Array.fill[Int](Q + 1)(-1)

    val zeros = ArrayBuffer[(Int, Int)]()
    var zero = -1

    rep(N) { i =>
      val a = A(i)
      if (L(a) == -1) L(a) = i
      R(a) = i

      if (a == 0) {
        if (zero == -1) zero = i
      } else if (zero != -1) {
        zeros += ((zero, i))
        zero = -1
      }
    }
    if (zero != -1) {
      zeros += ((zero, N))
    }

    var ok = true
    rep(Q, 1) { q =>
      if (L(q) != -1) {
        val ms = seg.query(L(q), R(q) + 1)
        ok &= ms == q
      }
    }

    // Qがでてくるか、0があれば
    val hasQ = L(Q) != -1
    ok &= hasQ || zeros.nonEmpty

    if (ok) {
      out.println("YES")

      def fillZero(zero: (Int, Int)): Unit = {
        val (l, r) = zero
        val x = if (l > 0) A(l - 1) else A(r)
        fillZeroBy(zero, x)
      }

      def fillZeroBy(zero: (Int, Int), x: Int): Unit = {
        val (l, r) = zero
        rep(r - l)(i => A(l + i) = x)
      }

      // 全部0の場合も!hasQかつzeros.length == 1 なのでこれで大丈夫
      if (!hasQ) {
        rep(zeros.length - 1)(i => fillZero(zeros(i)))
        fillZeroBy(zeros.last, Q) // 一箇所Qで埋める
      } else {
        rep(zeros.length)(i => fillZero(zeros(i)))
      }

      out.println(A.mkString(" "))
    } else {
      out.println("NO")
    }
  }

  class SegmentTree(n: Int) {
    private val N = {
      val a = Integer.highestOneBit(n)
      if (a == n) a else a << 1
    }
    private val dat: Array[Int] = Array.fill(2 * N - 1)(Integer.MAX_VALUE)

    def update(i: Int, a: Int): Unit = {
      var k = N - 1 + i
      dat(k) = a
      while(k > 0) {
        k = (k - 1) / 2
        dat(k) = min(dat(2 * k + 1), dat(2 * k + 2))
      }
    }

    def query(a: Int, b: Int): Int = {
      def step(k: Int, l: Int, r: Int): Int = {
        if (r <= a || b <= l) {
          Integer.MAX_VALUE
        } else if (a <= l && r <= b) {
          dat(k)
        } else {
          val vl = step(k * 2 + 1, l, (l + r) / 2)
          val vr = step(k * 2 + 2, (l + r) / 2, r)
          min(vl, vr)
        }
      }

      step(0, 0, N)
    }
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    rep(as.length)(i => s += as(i))
    s
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N, Q = ni()
    val A = na(N)

    val seg = new SegmentTree(N)
    rep(N) { i =>
      val a = A(i)
      seg.update(i, a)
    }

    val L = Array.fill[Int](Q + 1)(-1)
    val R = Array.fill[Int](Q + 1)(-1)

    rep(N) { i =>
      val a = A(i)
      if (L(a) == -1) L(a) = i
      R(a) = i
    }

    var ok = true
    rep(Q, 1) { q =>
      val ms = seg.query(L(q), R(q) + 1)
      ok &= ms == Integer.MAX_VALUE || ms == q
    }

    if (ok) {
      out.println("YES")
      rep(N - 1, 1) { i =>
        if (A(i) == 0) A(i) = A(i - 1)
      }

      rep_r(N - 1) { i =>
        if (A(i) == 0) A(i) = A(i + 1)
      }

      if (A(0) == 0) {
        rep(N)(i => A(i) = Q)
      }

      out.println(A.mkString(" "))
    } else {
      out.println("NO")
    }
  }

  class SegmentTree(n: Int) {
    private val N = {
      val a = Integer.highestOneBit(n)
      if (a == n) a else a << 1
    }
    private val dat: Array[Int] = Array.fill(2 * N - 1)(0)

    def update(i: Int, a: Int): Unit = {
      var k = N - 1 + i
      dat(k) = a
      while(k > 0) {
        k = (k - 1) / 2
        dat(k) = min(dat(2 * k + 1), dat(2 * k + 2))
      }
    }

    def query(a: Int, b: Int): Int = {
      def step(k: Int, l: Int, r: Int): Int = {
        if (r <= a || b <= l) {
          Integer.MAX_VALUE
        } else if (a <= l && r <= b) {
          dat(k)
        } else {
          val vl = step(k * 2 + 1, l, (l + r) / 2)
          val vr = step(k * 2 + 2, (l + r) / 2, r)
          min(vl, vr)
        }
      }

      step(0, 0, N)
    }
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    rep(as.length)(i => s += as(i))
    s
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N, Q = ni()
    val A = na(N)

    val seg = new SegmentTree(N)
    rep(N) { i =>
      val a = A(i)
      seg.update(i, a)
    }

    val L = Array.fill[Int](Q + 1)(-1)
    val R = Array.fill[Int](Q + 1)(-1)

    val zeros = ArrayBuffer[(Int, Int)]()
    var zero = -1

    rep(N) { i =>
      val a = A(i)
      if (L(a) == -1) L(a) = i
      R(a) = i

      if (a == 0) {
        if (zero == -1) zero = i
      } else if (zero != -1) {
        zeros += ((zero, i))
        zero = -1
      }
    }
    if (zero != -1) {
      zeros += ((zero, N))
    }

    var ok = true
    rep(Q, 1) { q =>
      val ms = seg.query(L(q), R(q) + 1)
      ok &= ms == Integer.MAX_VALUE || ms == q
    }

    // Qがでてくるか、0があれば
    val hasQ = L(Q) != -1
    ok &= hasQ || zeros.nonEmpty

    if (ok) {
      out.println("YES")

      def fillZero(zero: (Int, Int)): Unit = {
        val (l, r) = zero
        val x = if (l > 0) A(l - 1) else A(r)
        fillZeroBy(zero, x)
      }

      def fillZeroBy(zero: (Int, Int), x: Int): Unit = {
        val (l, r) = zero
        rep(r - l)(i => A(l + i) = x)
      }

      // 全部0の場合も!hasQかつzeros.length == 1 なのでこれで大丈夫
      if (!hasQ) {
        rep(zeros.length - 1)(i => fillZero(zeros(i)))
        fillZeroBy(zeros.last, Q) // 一箇所Qで埋める
      } else {
        rep(zeros.length)(i => fillZero(zeros(i)))
      }

      out.println(A.mkString(" "))
    } else {
      out.println("NO")
    }
  }

  class SegmentTree(n: Int) {
    private val N = {
      val a = Integer.highestOneBit(n)
      if (a == n) a else a << 1
    }
    private val dat: Array[Int] = Array.fill(2 * N - 1)(0)

    def update(i: Int, a: Int): Unit = {
      var k = N - 1 + i
      dat(k) = a
      while(k > 0) {
        k = (k - 1) / 2
        dat(k) = min(dat(2 * k + 1), dat(2 * k + 2))
      }
    }

    def query(a: Int, b: Int): Int = {
      def step(k: Int, l: Int, r: Int): Int = {
        if (r <= a || b <= l) {
          Integer.MAX_VALUE
        } else if (a <= l && r <= b) {
          dat(k)
        } else {
          val vl = step(k * 2 + 1, l, (l + r) / 2)
          val vr = step(k * 2 + 2, (l + r) / 2, r)
          min(vl, vr)
        }
      }

      step(0, 0, N)
    }
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    rep(as.length)(i => s += as(i))
    s
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N, Q = ni()
    val A = na(N)

    val seg = new SegmentTree(N)
    rep(N) { i =>
      val a = A(i)
      seg.update(i, a)
    }

    val L = Array.fill[Int](Q + 1)(-1)
    val R = Array.fill[Int](Q + 1)(-1)

    rep(N) { i =>
      val a = A(i)
      if (L(a) == -1) L(a) = i
      R(a) = i
    }

    var ok = true
    rep(Q, 1) { q =>
      val ms = seg.query(L(q), R(q) + 1)
      ok &= ms == Integer.MAX_VALUE || ms == q
    }

    if (ok) {
      out.println("YES")
      rep(N - 1, 1) { i =>
        if (A(i) == 0) A(i) = A(i - 1)
      }

      rep_r(N - 1) { i =>
        if (A(i) == 0) A(i) = A(i + 1)
      }

      if (A(0) == 0) {
        rep(N)(i => A(i) = 1)
      }

      out.println(A.mkString(" "))
    } else {
      out.println("NO")
    }
  }

  class SegmentTree(n: Int) {
    private val N = {
      val a = Integer.highestOneBit(n)
      if (a == n) a else a << 1
    }
    private val dat: Array[Int] = Array.fill(2 * N - 1)(0)

    def update(i: Int, a: Int): Unit = {
      var k = N - 1 + i
      dat(k) = a
      while(k > 0) {
        k = (k - 1) / 2
        dat(k) = min(dat(2 * k + 1), dat(2 * k + 2))
      }
    }

    def query(a: Int, b: Int): Int = {
      def step(k: Int, l: Int, r: Int): Int = {
        if (r <= a || b <= l) {
          Integer.MAX_VALUE
        } else if (a <= l && r <= b) {
          dat(k)
        } else {
          val vl = step(k * 2 + 1, l, (l + r) / 2)
          val vr = step(k * 2 + 2, (l + r) / 2, r)
          min(vl, vr)
        }
      }

      step(0, 0, N)
    }
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    rep(as.length)(i => s += as(i))
    s
  }
}

import java.util.StringTokenizer
import java.io.BufferedReader
import java.io.BufferedInputStream
import java.io.InputStreamReader
import java.io.ByteArrayInputStream
import java.io.InputStream

object CF_504_D {   var br = createBufferedReader(); var debugV = false

    //COMMENT ME !
//    runTest(Test.t1)
//    debugV = true
//    runFromFile("""C:\work\git\ap-codeforces\Codeforces\src\fb\aprokh\fb2018r2\jacks_candy_shop_2.txt""")

  def main(args: Array[String]): Unit = {
    //---------------------------- parameters reading
    val l1 = readLine
    val n = l1.int
    val Q = l1.int
    val arrLine = readLine
    val arr = new Array[Int](n)

    for(i <- 0 until n) {
      arr(i) = arrLine.int
    }

    val resArr = new Array[Int](n)
    var good = true
    for(qu <- Q to 1 by -1) {
      var started = false
      var finished = false
      for(i <- 0 until n) {
        (started, finished) match {
          case (false, false) => {
            if (arr(i) == qu) {
              started = true
              arr(i) = -1
              resArr(i) = qu
            }
          }
          case (true, false) => {
            if (arr(i) != qu && arr(i) != 0 && arr(i) != -1) {
              finished = true
            } else {
              if (arr(i) != -1)
                resArr(i) = qu
            }
          }
          case (true, true) => {
            if (arr(i) == qu) {
              good = false
            }
          }
        }
      }
      debug("After: " + qu)
    }
    var last = resArr(n-1)
    if (last == 0) last = Q
    for(i <- n-1 to 0 by -1) {
      if (resArr(i) == 0) {
        resArr(i) = last
      }
      last = resArr(i)
    }
    if (good) {
      outLn("YES")
      outLn(resArr.mkString(" "))
    } else {
      outLn("NO")
    }

    debug("================= RESULT ================== ")
    finish
  }

  //============================ service code ======================

//  var file:File = null
  val resultStr = new StringBuilder
  def outLn(str:String) = resultStr.append(str).append("\n")
  def outLn(number:Integer) = resultStr.append(number+"").append("\n")
  def finish() {
//    if (file == null || !devEnv) {
      println(resultStr.toString())
      Console.flush()
//    } else {
//      file.writeAll(resultStr.toString())
//    }
  }

  def readLine() = new Line
  class Line {
    val fullLine = br.readLine()
    val tok = new StringTokenizer(fullLine, " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()
  }

  def createBufferedReader(inst:InputStream = System.in): BufferedReader = {
    val bis = if (inst == null) new BufferedInputStream(System.in) else new BufferedInputStream(inst);
    new BufferedReader(new InputStreamReader(bis));
  }

  def runTest(str:String) = if (devEnv) {
    br = createBufferedReader(new ByteArrayInputStream(str.trim.getBytes("ISO-8859-1")))
  }

//  def runFromFile(fileName: String) = if (devEnv) {
//    br = createBufferedReader(new FileInputStream(fileName))
//  }

  def debug(x: => String) = if (debugV && devEnv) println(x) // nullary function

  lazy val devEnv = this.getClass.getCanonicalName.contains(".")

//============================================================================================
object Test {

val sa1 = """
4 3
1 0 2 3
"""

val sa2 = """
"""

val t1 = """
4 3
0 1 2 3
"""

}

}

import java.util.StringTokenizer
import java.io.BufferedReader
import java.io.BufferedInputStream
import java.io.InputStreamReader
import java.io.ByteArrayInputStream
import java.io.InputStream

object CF_504_D {   var br = createBufferedReader(); var debugV = false

    //COMMENT ME !
//    runTest(Test.t1)
//    debugV = true
//    runFromFile("""C:\work\git\ap-codeforces\Codeforces\src\fb\aprokh\fb2018r2\jacks_candy_shop_2.txt""")

  def main(args: Array[String]): Unit = {
    //---------------------------- parameters reading
    val l1 = readLine
    val n = l1.int
    val Q = l1.int
    val arrLine = readLine
    val arr = new Array[Int](n)

    for(i <- 0 until n) {
      arr(i) = arrLine.int
    }

//    if (arr(0) == 1912) {
//      var acc = ""
//      for(i <- 0 until n) {
//        acc += arr(i) + " "
//        if (i % 50 == 0) {
//          println(acc)
//          acc = ""
//        }
//      }
//    }

    val resArr = new Array[Int](n)
    var good = true
    for(qu <- Q to 1 by -1) {
      var started = false
      var finished = false
      for(i <- 0 until n) {
        (started, finished) match {
          case (false, false) => {
            if (arr(i) == qu) {
              started = true
              arr(i) = -1
              resArr(i) = qu
            }
          }
          case (true, false) => {
            if (arr(i) != qu && arr(i) != 0 && arr(i) != -1) {
              finished = true
            } else { //still continue
              if (arr(i) != -1) {
                resArr(i) = qu
                arr(i) = -1
              }
            }
          }
          case (true, true) => {
            if (arr(i) == qu) {
              good = false
              if (arr(0) == 1912) {
                println("Break on " + qu + " i=" + i)
              }
            }
          }
        }
      }
      debug("After: " + qu)
    }
    var last = resArr(n-1)
    if (last == 0) last = Q
    for(i <- n-1 to 0 by -1) {
      if (resArr(i) == 0) {
        resArr(i) = last
      }
      last = resArr(i)
    }
    var lastPresent = false
    for( i <- 0 until n) {
      if (resArr(i) == Q) lastPresent = true
    }
    if (!lastPresent) good = false

    if (good) {
      outLn("YES")
      outLn(resArr.mkString(" "))
    } else {
      outLn("NO")
    }

    debug("================= RESULT ================== ")
    finish
  }

  //============================ service code ======================

//  var file:File = null
  val resultStr = new StringBuilder
  def outLn(str:String) = resultStr.append(str).append("\n")
  def outLn(number:Integer) = resultStr.append(number+"").append("\n")
  def finish() {
//    if (file == null || !devEnv) {
      println(resultStr.toString())
      Console.flush()
//    } else {
//      file.writeAll(resultStr.toString())
//    }
  }

  def readLine() = new Line
  class Line {
    val fullLine = br.readLine()
    val tok = new StringTokenizer(fullLine, " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()
  }

  def createBufferedReader(inst:InputStream = System.in): BufferedReader = {
    val bis = if (inst == null) new BufferedInputStream(System.in) else new BufferedInputStream(inst);
    new BufferedReader(new InputStreamReader(bis));
  }

  def runTest(str:String) = if (devEnv) {
    br = createBufferedReader(new ByteArrayInputStream(str.trim.getBytes("ISO-8859-1")))
  }

//  def runFromFile(fileName: String) = if (devEnv) {
//    br = createBufferedReader(new FileInputStream(fileName))
//  }

  def debug(x: => String) = if (debugV && devEnv) println(x) // nullary function

  lazy val devEnv = this.getClass.getCanonicalName.contains(".")

//============================================================================================
object Test {

val sa1 = """
4 3
1 0 2 3
"""

val sa2 = """
"""

val t1 = """
4 3
0 1 2 3
"""

}

}

import java.util.StringTokenizer
import java.io.BufferedReader
import java.io.BufferedInputStream
import java.io.InputStreamReader
import java.io.ByteArrayInputStream
import java.io.InputStream

object CF_504_D {   var br = createBufferedReader(); var debugV = false

    //COMMENT ME !
//    runTest(Test.t1)
//    debugV = true
//    runFromFile("""C:\work\git\ap-codeforces\Codeforces\src\fb\aprokh\fb2018r2\jacks_candy_shop_2.txt""")

  def main(args: Array[String]): Unit = {
    //---------------------------- parameters reading
    val l1 = readLine
    val n = l1.int
    val Q = l1.int
    val arrLine = readLine
    val arr = new Array[Int](n)

    for(i <- 0 until n) {
      arr(i) = arrLine.int
    }

    val resArr = new Array[Int](n)
    var good = true
    for(qu <- Q to 1 by -1) {
      var started = false
      var finished = false
      for(i <- 0 until n) {
        (started, finished) match {
          case (false, false) => {
            if (arr(i) == qu) {
              started = true
              arr(i) = -1
              resArr(i) = qu
            }
          }
          case (true, false) => {
            if (arr(i) != qu && arr(i) != 0 && arr(i) != -1) {
              finished = true
            } else {
              if (arr(i) != -1)
                resArr(i) = qu
            }
          }
          case (true, true) => {
            if (arr(i) == qu) {
              good = false
            }
          }
        }
      }
      debug("After: " + qu)
    }
    var last = resArr(n-1)
    if (last == 0) last = 1
    for(i <- n-1 to 0 by -1) {
      if (resArr(i) == 0) {
        resArr(i) = last
      }
      last = resArr(i)
    }
    if (good) {
      outLn("YES")
      outLn(resArr.mkString(" "))
    } else {
      outLn("NO")
    }

    debug("================= RESULT ================== ")
    finish
  }

  //============================ service code ======================

//  var file:File = null
  val resultStr = new StringBuilder
  def outLn(str:String) = resultStr.append(str).append("\n")
  def outLn(number:Integer) = resultStr.append(number+"").append("\n")
  def finish() {
//    if (file == null || !devEnv) {
      println(resultStr.toString())
      Console.flush()
//    } else {
//      file.writeAll(resultStr.toString())
//    }
  }

  def readLine() = new Line
  class Line {
    val fullLine = br.readLine()
    val tok = new StringTokenizer(fullLine, " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()
  }

  def createBufferedReader(inst:InputStream = System.in): BufferedReader = {
    val bis = if (inst == null) new BufferedInputStream(System.in) else new BufferedInputStream(inst);
    new BufferedReader(new InputStreamReader(bis));
  }

  def runTest(str:String) = if (devEnv) {
    br = createBufferedReader(new ByteArrayInputStream(str.trim.getBytes("ISO-8859-1")))
  }

//  def runFromFile(fileName: String) = if (devEnv) {
//    br = createBufferedReader(new FileInputStream(fileName))
//  }

  def debug(x: => String) = if (debugV && devEnv) println(x) // nullary function

  lazy val devEnv = this.getClass.getCanonicalName.contains(".")

//============================================================================================
object Test {

val sa1 = """
4 3
1 0 2 3
"""

val sa2 = """
"""

val t1 = """
4 3
0 1 2 3
"""

}

}

import java.util.StringTokenizer
import java.io.BufferedReader
import java.io.BufferedInputStream
import java.io.InputStreamReader
import java.io.ByteArrayInputStream
import java.io.InputStream
import java.security.SecureRandom

object CF_504_D {   var br = createBufferedReader(); var debugV = false

    //COMMENT ME !
//    runTest(Test.gen)
//    debugV = true
//    runFromFile("""C:\work\git\ap-codeforces\Codeforces\src\fb\aprokh\fb2018r2\jacks_candy_shop_2.txt""")

  def main(args: Array[String]): Unit = {
    //---------------------------- parameters reading
    val l1 = readLine
    val n = l1.int
    val Q = l1.int
    val arrLine = readLine
    val arr = new Array[Int](n)
    val startTime = System.currentTimeMillis()

    class Cell(val ind: Int, val value: Int) {
      var prev: Cell = null
      var next: Cell = null
    }

    class ArrList() {
      var first: Cell = null
      var last: Cell = null

      def add(cc: Cell) {
        if (first == null) {
          first = cc
        } else {
          last.next = cc
          cc.prev = last
        }
        last = cc
      }
      def remove(cc: Cell) {
        if (cc.prev != null) {
            cc.prev.next = cc.next
        }
        if (cc.next != null) {
          cc.next.prev = cc.prev
        }
        if (cc == first) {
          first = cc.next
        }
        if (cc == last) {
          last = cc.prev
        }
      }
      def mkString: String= {
        var cur = first
        var res = ""
        while (cur != null) {
//          res += cur.ind+"-"+cur.value + ","
          res += cur.value + ","
          cur = cur.next
        }
        res
      }
    }
    val aList = new ArrList()

    for(i <- 0 until n) {
      val vv = arrLine.int
      arr(i) = vv
    }

    var cur = aList.first
    while (cur != null) {
      print(cur.value + " ")
      cur = cur.next
    }
    println

//    if (arr(0) == 1912) {
//      var acc = ""
//      for(i <- 0 until n) {
//        acc += arr(i) + " "
//        if (i % 50 == 0) {
//          println(acc)
//          acc = ""
//        }
//      }
//    }

    var lastPresent = false
    var zeroInd = -1
    for( i <- 0 until n) {
      if (arr(i) == Q) lastPresent = true
      if (arr(i) == 0) zeroInd = i
    }
    if (!lastPresent && zeroInd != -1) arr(zeroInd) = Q

    //copy to linked list
    val starts = new Array[Cell](Q+1)
    val counts = new Array[Int](Q+1)
    for(i <- 0 until n) {
      val q = arr(i)
      val cc = new Cell(i, q)
      if (starts(q) == null) { starts(q) = cc }
      counts(q) += 1
      aList.add(cc)
    }

    val resArr = new Array[Int](n)
    var good = true

//    def calc(): Unit = {
//      for(qu <- Q to 1 by -1) {
//        var started = false
//        var finished = false
//        for(i <- 0 until n) {
//          (started, finished) match {
//            case (false, false) => {
//              if (arr(i) == qu) {
//                started = true
//                arr(i) = -1
//                resArr(i) = qu
//              }
//            }
//            case (true, false) => {
//              if (arr(i) != qu && arr(i) != 0 && arr(i) != -1) {
//                finished = true
//              } else { //still continue
//                if (arr(i) != -1) {
//                  resArr(i) = qu
//                  arr(i) = -1
//                }
//              }
//            }
//            case (true, true) => {
//              if (arr(i) == qu) {
//                good = false
//  //              if (arr(0) == 1912) {
//  //                println("Break on " + qu + " i=" + i)
//  //              }
//              }
//            }
//          }
//          if (!good) return
//        }
////        debug("After: " + qu)
//      }
//    }
//    calc()

//    debug("After query " + "0" + ": " + aList.mkString)

    val sss = System.currentTimeMillis()
    var totalSteps = 0
    def calc2(): Unit = {
      for(qu <- Q to 1 by -1) {
        var started = false
        var finished = false
        var curCell = starts(qu)
        while(good && curCell != null && counts(qu) > 0) {
          totalSteps += 1
          (started, finished) match {
            case (false, false) => {
              if (curCell.value == qu) {
                started = true
                aList.remove(curCell)
                resArr(curCell.ind) = qu
                counts(qu) -= 1
//                debug("Removed first cell" + curCell)
              }
            }
            case (true, false) => {
              if (curCell.value != qu && curCell.value != 0) {
                finished = true
//                debug("finished")
              } else { //still continue
                aList.remove(curCell)
                resArr(curCell.ind) = qu
                counts(qu) -= 1
//                debug("Removed subseq cell" + curCell)
              }
            }
            case (true, true) => {
              if (curCell.value == qu) {
//                debug("Fail at secondary piece: " + qu)
                good = false
              }
            }
          }
//          debug(" - After step " + qu + ": " + aList.mkString)
          curCell = curCell.next
        }
//        debug("After query " + qu + ": " + aList.mkString)
      }
    }
    calc2
    val ddd = System.currentTimeMillis() - sss
    debug("calc2 dur " + ddd + "  steps=" + totalSteps)

    var last = resArr(n-1)
    if (last == 0) last = Q
    for(i <- n-1 to 0 by -1) {
      if (resArr(i) == 0) {
        resArr(i) = last
      }
      last = resArr(i)
    }
    lastPresent = false
    for( i <- 0 until n) {
      if (resArr(i) == Q) lastPresent = true
    }
    if (!lastPresent) {
//      debug("Fail at top query absent")
      good = false
    }

    if (good) {
      outLn("YES")
      outLn(resArr.mkString(" "))
    } else {
      outLn("NO")
    }

    debug("================= RESULT ================== ")
    val endTime = System.currentTimeMillis() - startTime
    debug("Exec time: " + endTime)
    finish
  }

  //============================ service code ======================

//  var file:File = null
  val resultStr = new StringBuilder
  def outLn(str:String) = resultStr.append(str).append("\n")
  def outLn(number:Integer) = resultStr.append(number+"").append("\n")
  def finish() {
//    if (file == null || !devEnv) {
      println(resultStr.toString())
      Console.flush()
//    } else {
//      file.writeAll(resultStr.toString())
//    }
  }

  def readLine() = new Line
  class Line {
    val fullLine = br.readLine()
    val tok = new StringTokenizer(fullLine, " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()
  }

  def createBufferedReader(inst:InputStream = System.in): BufferedReader = {
    val bis = if (inst == null) new BufferedInputStream(System.in) else new BufferedInputStream(inst);
    new BufferedReader(new InputStreamReader(bis));
  }

  def runTest(str:String) = if (devEnv) {
    br = createBufferedReader(new ByteArrayInputStream(str.trim.getBytes("ISO-8859-1")))
  }

//  def runFromFile(fileName: String) = if (devEnv) {
//    br = createBufferedReader(new FileInputStream(fileName))
//  }

  def debug(x: => String) = if (debugV && devEnv) println(x) // nullary function

  lazy val devEnv = this.getClass.getCanonicalName.contains(".")

//============================================================================================
object Test {

val sa1 = """
4 3
1 0 2 3
"""

val sa2 = """
"""

val t1 = """
4 3
1 0 2 3
"""

val t2 = """
20 20
17 17 19 19 17 20 20 17 16 16 16 16 16 18 18 18 18 18 6 0
"""

def gen = {
  val runStart = System.currentTimeMillis()
  val n = 200000
  val q = 200000
  val rr = new SecureRandom
  val arr = new Array[Int](n)
  for(i <- 1 to q) {
    val start = rr.nextInt(n-1)
    val length = 1 //rr.nextInt(n-start-1)
//    val length = n-q
    val end = length + start
    for (j <- start to end) {
      arr(j) = i
    }
  }
  val res = s"$n $q" + "\n" + arr.mkString(" ")
  val runEnd = System.currentTimeMillis() - runStart
  println("Gen time " + runEnd)
  println(res)
  res
}

}

}

import java.util.StringTokenizer
import java.io.BufferedReader
import java.io.BufferedInputStream
import java.io.InputStreamReader
import java.io.ByteArrayInputStream
import java.io.InputStream

object CF_504_D {   var br = createBufferedReader(); var debugV = false

    //COMMENT ME !
//    runTest(Test.t1)
//    debugV = true
//    runFromFile("""C:\work\git\ap-codeforces\Codeforces\src\fb\aprokh\fb2018r2\jacks_candy_shop_2.txt""")

  def main(args: Array[String]): Unit = {
    //---------------------------- parameters reading
    val l1 = readLine
    val n = l1.int
    val Q = l1.int
    val arrLine = readLine
    val arr = new Array[Int](n)

    for(i <- 0 until n) {
      arr(i) = arrLine.int
    }

    val resArr = new Array[Int](n)
    var good = true
    for(qu <- Q to 1 by -1) {
      var started = false
      var finished = false
      for(i <- 0 until n) {
        (started, finished) match {
          case (false, false) => {
            if (arr(i) == qu) {
              started = true
              arr(i) = -1
              resArr(i) = qu
            }
          }
          case (true, false) => {
            if (arr(i) != qu && arr(i) != 0 && arr(i) != -1) {
              finished = true
            } else { //still continue
              if (arr(i) != -1) {
                resArr(i) = qu
                arr(i) = -1
              }
            }
          }
          case (true, true) => {
            if (arr(i) == qu) {
              good = false
            }
          }
        }
      }
      debug("After: " + qu)
    }
    var last = resArr(n-1)
    if (last == 0) last = Q
    for(i <- n-1 to 0 by -1) {
      if (resArr(i) == 0) {
        resArr(i) = last
      }
      last = resArr(i)
    }
    var lastPresent = false
    for( i <- 0 until n) {
      if (resArr(i) == Q) lastPresent = true
    }
    if (!lastPresent) good = false

    if (good) {
      outLn("YES")
      outLn(resArr.mkString(" "))
    } else {
      outLn("NO")
    }

    debug("================= RESULT ================== ")
    finish
  }

  //============================ service code ======================

//  var file:File = null
  val resultStr = new StringBuilder
  def outLn(str:String) = resultStr.append(str).append("\n")
  def outLn(number:Integer) = resultStr.append(number+"").append("\n")
  def finish() {
//    if (file == null || !devEnv) {
      println(resultStr.toString())
      Console.flush()
//    } else {
//      file.writeAll(resultStr.toString())
//    }
  }

  def readLine() = new Line
  class Line {
    val fullLine = br.readLine()
    val tok = new StringTokenizer(fullLine, " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()
  }

  def createBufferedReader(inst:InputStream = System.in): BufferedReader = {
    val bis = if (inst == null) new BufferedInputStream(System.in) else new BufferedInputStream(inst);
    new BufferedReader(new InputStreamReader(bis));
  }

  def runTest(str:String) = if (devEnv) {
    br = createBufferedReader(new ByteArrayInputStream(str.trim.getBytes("ISO-8859-1")))
  }

//  def runFromFile(fileName: String) = if (devEnv) {
//    br = createBufferedReader(new FileInputStream(fileName))
//  }

  def debug(x: => String) = if (debugV && devEnv) println(x) // nullary function

  lazy val devEnv = this.getClass.getCanonicalName.contains(".")

//============================================================================================
object Test {

val sa1 = """
4 3
1 0 2 3
"""

val sa2 = """
"""

val t1 = """
4 3
0 1 2 3
"""

}

}

import java.util.StringTokenizer
import java.io.BufferedReader
import java.io.BufferedInputStream
import java.io.InputStreamReader
import java.io.ByteArrayInputStream
import java.io.InputStream

object CF_504_D {   var br = createBufferedReader(); var debugV = false

    //COMMENT ME !
//    runTest(Test.t1)
//    debugV = true
//    runFromFile("""C:\work\git\ap-codeforces\Codeforces\src\fb\aprokh\fb2018r2\jacks_candy_shop_2.txt""")

  def main(args: Array[String]): Unit = {
    //---------------------------- parameters reading
    val l1 = readLine
    val n = l1.int
    val Q = l1.int
    val arrLine = readLine
    val arr = new Array[Int](n)

    for(i <- 0 until n) {
      arr(i) = arrLine.int
    }

    if (arr(0) == 1912) {
      var acc = ""
      for(i <- 0 until n) {
        acc += arr(i) + " "
        if (i % 50 == 0) {
          println(acc)
          acc = ""
        }
      }
    }

    val resArr = new Array[Int](n)
    var good = true
    for(qu <- Q to 1 by -1) {
      var started = false
      var finished = false
      for(i <- 0 until n) {
        (started, finished) match {
          case (false, false) => {
            if (arr(i) == qu) {
              started = true
              arr(i) = -1
              resArr(i) = qu
            }
          }
          case (true, false) => {
            if (arr(i) != qu && arr(i) != 0 && arr(i) != -1) {
              finished = true
            } else { //still continue
              if (arr(i) != -1) {
                resArr(i) = qu
                arr(i) = -1
              }
            }
          }
          case (true, true) => {
            if (arr(i) == qu) {
              good = false
            }
          }
        }
      }
      debug("After: " + qu)
    }
    var last = resArr(n-1)
    if (last == 0) last = Q
    for(i <- n-1 to 0 by -1) {
      if (resArr(i) == 0) {
        resArr(i) = last
      }
      last = resArr(i)
    }
    var lastPresent = false
    for( i <- 0 until n) {
      if (resArr(i) == Q) lastPresent = true
    }
    if (!lastPresent) good = false

    if (good) {
      outLn("YES")
      outLn(resArr.mkString(" "))
    } else {
      outLn("NO")
    }

    debug("================= RESULT ================== ")
    finish
  }

  //============================ service code ======================

//  var file:File = null
  val resultStr = new StringBuilder
  def outLn(str:String) = resultStr.append(str).append("\n")
  def outLn(number:Integer) = resultStr.append(number+"").append("\n")
  def finish() {
//    if (file == null || !devEnv) {
      println(resultStr.toString())
      Console.flush()
//    } else {
//      file.writeAll(resultStr.toString())
//    }
  }

  def readLine() = new Line
  class Line {
    val fullLine = br.readLine()
    val tok = new StringTokenizer(fullLine, " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()
  }

  def createBufferedReader(inst:InputStream = System.in): BufferedReader = {
    val bis = if (inst == null) new BufferedInputStream(System.in) else new BufferedInputStream(inst);
    new BufferedReader(new InputStreamReader(bis));
  }

  def runTest(str:String) = if (devEnv) {
    br = createBufferedReader(new ByteArrayInputStream(str.trim.getBytes("ISO-8859-1")))
  }

//  def runFromFile(fileName: String) = if (devEnv) {
//    br = createBufferedReader(new FileInputStream(fileName))
//  }

  def debug(x: => String) = if (debugV && devEnv) println(x) // nullary function

  lazy val devEnv = this.getClass.getCanonicalName.contains(".")

//============================================================================================
object Test {

val sa1 = """
4 3
1 0 2 3
"""

val sa2 = """
"""

val t1 = """
4 3
0 1 2 3
"""

}

}

import java.util.StringTokenizer
import java.io.BufferedReader
import java.io.BufferedInputStream
import java.io.InputStreamReader
import java.io.ByteArrayInputStream
import java.io.InputStream
import java.security.SecureRandom

object CF_504_D {   var br = createBufferedReader(); var debugV = false

    //COMMENT ME !
    runTest(Test.t7)
//    debugV = true
//    runFromFile("""C:\work\git\ap-codeforces\Codeforces\src\fb\aprokh\fb2018r2\jacks_candy_shop_2.txt""")

  def main(args: Array[String]): Unit = {
    //---------------------------- parameters reading
    val l1 = readLine
    val n = l1.int
    val Q = l1.int
    val arrLine = readLine
    val arr = new Array[Int](n)
    val startTime = System.currentTimeMillis()

    class Cell(val ind: Int, val value: Int) {
      var prev: Cell = null
      var next: Cell = null
    }

    class ArrList() {
      var first: Cell = null
      var last: Cell = null

      def add(cc: Cell) {
        if (first == null) {
          first = cc
        } else {
          last.next = cc
          cc.prev = last
        }
        last = cc
      }
      def remove(cc: Cell) {
        if (cc.prev != null) {
            cc.prev.next = cc.next
        }
        if (cc.next != null) {
          cc.next.prev = cc.prev
        }
        if (cc == first) {
          first = cc.next
        }
        if (cc == last) {
          last = cc.prev
        }
      }
      def mkString: String= {
        var cur = first
        var res = ""
        while (cur != null) {
//          res += cur.ind+"-"+cur.value + ","
          res += cur.value + ","
          cur = cur.next
        }
        res
      }
    }
    val aList = new ArrList()

    for(i <- 0 until n) {
      val vv = arrLine.int
      arr(i) = vv
    }

    var cur = aList.first
    while (cur != null) {
      print(cur.value + " ")
      cur = cur.next
    }
    println

//    if (arr(0) == 1912) {
//      var acc = ""
//      for(i <- 0 until n) {
//        acc += arr(i) + " "
//        if (i % 50 == 0) {
//          println(acc)
//          acc = ""
//        }
//      }
//    }

    var lastPresent = false
    var zeroInd = -1
    for( i <- 0 until n) {
      if (arr(i) == Q) lastPresent = true
      if (arr(i) == 0) zeroInd = i
    }
    if (!lastPresent && zeroInd != -1) arr(zeroInd) = Q

    //copy to linked list
    val starts = new Array[Cell](Q+1)
    val counts = new Array[Int](Q+1)
    for(i <- 0 until n) {
      val q = arr(i)
      val cc = new Cell(i, q)
      if (starts(q) == null) { starts(q) = cc }
      counts(q) += 1
      aList.add(cc)
    }

    val resArr = new Array[Int](n)
    var good = true

//    def calc(): Unit = {
//      for(qu <- Q to 1 by -1) {
//        var started = false
//        var finished = false
//        for(i <- 0 until n) {
//          (started, finished) match {
//            case (false, false) => {
//              if (arr(i) == qu) {
//                started = true
//                arr(i) = -1
//                resArr(i) = qu
//              }
//            }
//            case (true, false) => {
//              if (arr(i) != qu && arr(i) != 0 && arr(i) != -1) {
//                finished = true
//              } else { //still continue
//                if (arr(i) != -1) {
//                  resArr(i) = qu
//                  arr(i) = -1
//                }
//              }
//            }
//            case (true, true) => {
//              if (arr(i) == qu) {
//                good = false
//  //              if (arr(0) == 1912) {
//  //                println("Break on " + qu + " i=" + i)
//  //              }
//              }
//            }
//          }
//          if (!good) return
//        }
////        debug("After: " + qu)
//      }
//    }
//    calc()

    debug("After query " + "0" + ": " + aList.mkString)

    val sss = System.currentTimeMillis()
    var totalSteps = 0
    def calc2(): Unit = {
      for(qu <- Q to 1 by -1) {
        var started = false
        var finished = false
        var curCell = starts(qu)
        while(good && curCell != null && counts(qu) > 0) {
          totalSteps += 1
          (started, finished) match {
            case (false, false) => {
              if (curCell.value == qu) {
                started = true
                aList.remove(curCell)
                resArr(curCell.ind) = qu
                counts(qu) -= 1
//                debug("Removed first cell" + curCell)
              }
            }
            case (true, false) => {
              if (curCell.value != qu && curCell.value != 0) {
                finished = true
//                debug("finished")
              } else { //still continue
                aList.remove(curCell)
                resArr(curCell.ind) = qu
                if (curCell.value == qu) { counts(qu) -= 1 }
//                debug("Removed subseq cell" + curCell)
              }
            }
            case (true, true) => {
              if (curCell.value == qu) {
                debug("Fail at secondary piece: " + qu)
                good = false
              }
            }
          }
//          debug(" - After step " + qu + ": " + aList.mkString)
          curCell = curCell.next
        }
        debug("After query " + qu + ": " + aList.mkString)
      }
    }
    calc2
    val ddd = System.currentTimeMillis() - sss
    debug("calc2 dur " + ddd + "  steps=" + totalSteps)

    var last = resArr(n-1)
    if (last == 0) last = Q
    for(i <- n-1 to 0 by -1) {
      if (resArr(i) == 0) {
        resArr(i) = last
      }
      last = resArr(i)
    }
    lastPresent = false
    for( i <- 0 until n) {
      if (resArr(i) == Q) lastPresent = true
    }
    if (!lastPresent) {
      debug("Fail at top query absent")
      good = false
    }

    if (good) {
      outLn("YES")
      outLn(resArr.mkString(" "))
    } else {
      outLn("NO")
    }

    debug("================= RESULT ================== ")
    val endTime = System.currentTimeMillis() - startTime
    debug("Exec time: " + endTime)
    finish
  }

  //============================ service code ======================

//  var file:File = null
  val resultStr = new StringBuilder
  def outLn(str:String) = resultStr.append(str).append("\n")
  def outLn(number:Integer) = resultStr.append(number+"").append("\n")
  def finish() {
//    if (file == null || !devEnv) {
      println(resultStr.toString())
      Console.flush()
//    } else {
//      file.writeAll(resultStr.toString())
//    }
  }

  def readLine() = new Line
  class Line {
    val fullLine = br.readLine()
    val tok = new StringTokenizer(fullLine, " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()
  }

  def createBufferedReader(inst:InputStream = System.in): BufferedReader = {
    val bis = if (inst == null) new BufferedInputStream(System.in) else new BufferedInputStream(inst);
    new BufferedReader(new InputStreamReader(bis));
  }

  def runTest(str:String) = if (devEnv) {
    br = createBufferedReader(new ByteArrayInputStream(str.trim.getBytes("ISO-8859-1")))
  }

//  def runFromFile(fileName: String) = if (devEnv) {
//    br = createBufferedReader(new FileInputStream(fileName))
//  }

  def debug(x: => String) = if (debugV && devEnv) println(x) // nullary function

  lazy val devEnv = this.getClass.getCanonicalName.contains(".")

//============================================================================================
object Test {

val sa1 = """
4 3
1 0 2 3
"""

val sa2 = """
"""

val t7 = """
50 2
0 1 0 1 0 0 1 0 1 1 0 1 1 1 2 2 0 2 0 2 0 2 0 0 2 2 2 0 0 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 1 0 1 0 0
"""

val m1 = """
4 3
1 0 2 3
"""

val m2 = """
20 20
17 17 19 19 17 20 20 17 16 16 16 16 16 18 18 18 18 18 6 0
"""

def gen = {
  val runStart = System.currentTimeMillis()
  val n = 200000
  val q = 200000
  val rr = new SecureRandom
  val arr = new Array[Int](n)
  for(i <- 1 to q) {
    val start = rr.nextInt(n-1)
    val length = 1 //rr.nextInt(n-start-1)
//    val length = n-q
    val end = length + start
    for (j <- start to end) {
      arr(j) = i
    }
  }
  val res = s"$n $q" + "\n" + arr.mkString(" ")
  val runEnd = System.currentTimeMillis() - runStart
  println("Gen time " + runEnd)
  println(res)
  res
}

}

}