import scala.io.StdIn.readLine import scala.collection.mutable.PriorityQueue import scala.annotation.tailrec // PriorityQueue[Long]()(scala.math.Ordering.Long.reverse) package net.pushl { package number { // Prime (Prime.scala) // Number (Number.scala) } package string { // RollingHash (RollingHash.scala) } object EnRich { implicit class AString(val self : String) extends AnyVal { def splitToIntArray = self.split(" ").map(_.toInt) } } } import net.pushl.EnRich._ object Main { def main(args : Array[String]) : Unit = { val c = readLine().toInt val n = readLine().toInt val a = readLine().splitToIntArray val v = Array.fill[Option[Int]](c+1)(None) v(0) = Some(0) for(i <- a){ for(k <- i to c){ (v(k),v(k-i)) match { case (Some(a),Some(b)) => v(k) = Some(a min (b+1)) case (None ,Some(b)) => v(k) = Some(b+1) case (_ ,None ) => {} } } } val out = v(c) match { case Some(k) => k case None => -1 } println(out) } }