This page is still under construction.

Parts of this page are still being built. What you see may change.

Time on Task

Time limit1sMemory limit128 MB

Summary
Given a time limit and chore durations, find the largest number of chores that can be completed in any order.
Level

Easy2 of 10

Topics
Greedy, Sorting
Solved
No attempts yet

Problem

A parent has asked you to do your chores.

Each chore takes a certain amount of time, and you can only do one chore at a time. The time you are given may not be enough to finish every chore. You may do the chores in any order you like.

Determine the largest number of chores you can finish within the given amount of time.

Input

The first line contains an integer TT (0≤T≤1000000 \le T \le 100000), the total number of minutes you have available for your chores.

The second line contains an integer CC (0≤C≤1000 \le C \le 100), the number of chores you may choose from. Each of the next CC lines contains a positive integer: the number of minutes needed for that chore. Each chore takes at most 100000100000 minutes.

Output

Output the maximum number of chores that can be finished within the time limit TT.

Hint

For example, suppose the time limit is 66 minutes and there are 33 chores taking 33, 66, and 33 minutes. The answer is 22, because only two chores (the first and the third) can be finished within 66 minutes, and it is impossible to finish all three.

Examples1

  1. Example 1

    Input
    6
    3
    3
    6
    3
    
    Expected output
    2