import java.util.Scanner

object Main extends App {

    val scanner = new Scanner(System.in)
    var n = scanner.nextInt()
    val arrayC: Array[Int] = {
        val m = scanner.nextInt()
        new Array[Int](m)
    }
    input(arrayC.length)
    System.out.println(result(0))

    def input(i: Int): Unit = {
        if (i == 0) return

        arrayC(i - 1) = scanner.nextInt()
        input(i - 1)
    }

    def result(r: Int): Int = {
        n -= arrayC(find(0))
        if (n == 0) {
            return r
        }
        return result(r + 1)
    }

    def find(i: Int): Int = {
        if (arrayC(i) <= n) {
            return i
        }
        return find(i + 1)
    }
}