count = 0
$n = 0
$m = 0
coin_str = ""
STDIN.each_line {|line|
  if count == 0
    count = 1
    n_m = line.split " "
    $n = n_m[0].to_i
    $m = n_m[1].to_i
  end

  coin_str = line
}

$coin_list = coin_str.split " "

def solve i, n, count
  if n == 0
    return count
  end

  if i == $m
    return $m + 1
  end

  result1 = result2 = $m + 1
  result1 = solve i + 1, n, count

  tmp = n - $coin_list[i].to_i
  if tmp >= 0
    result2 = solve i + 1, tmp, count + 1
  end

  return (result1 > result2) ? result2 : result1;
end

puts solve 0, $n, 1

