package main import ( "fmt" "sort" ) func main() { var l, n int var w []int fmt.Scan(&l, &n) var t int for i := 0; i < n; i++ { fmt.Scan(&t) w = append(w, t) } sort.Ints(w) var crt, cnt int for _, v := range w { if crt+v > l { break } cnt++ crt += v } fmt.Println(cnt) }