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
    next
  end

  coin_str = line
}

$min_count = $m + 1
$coin_list = coin_str.split " "
$result = 0
def solve i, n, count
  if i == $m
    return $m + 1
  end

  if n == 0
    return count
  end

  if count > $min_count
    return $min_count
  end

  count1 = count2 = count3 = count4 = $m + 1
  count2 = solve i + 1, n, count
  $min_count = $min_count > count2 ? count2 : $min_count;


  coin = $coin_list[i].to_i
  tmp = n - coin
  if tmp >= 0
    count3 = solve i, tmp, count + 1
    $min_count = $min_count > count3 ? count3 : $min_count;
    count4 = solve i + 1, tmp , count + 1
    $min_count = $min_count > count4 ? count4 : $min_count;
  end

  return $min_count
end

puts solve 0, $n, 0

