using System;
using System.Linq;

namespace StudyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            int l = int.Parse(Console.ReadLine());
            int n = int.Parse(Console.ReadLine());
            var wlist = Console.ReadLine().Trim().Split(' ')
                .Select(v => int.Parse(v)).OrderBy(v => v);

            int count = 0;
            int total = 0;

            foreach (var w in wlist)
            {
                total += w;
                if (l >= total)
                    count++;
                else
                    break;
            }
            Console.WriteLine(count);
        }
    }
}