// namespaceは環境に応じて変更する
using System.Collections.Generic;
class Program
{
///
/// コンストラクタ
///
static void Main()
{
int l = int.Parse(Console.ReadLine()!);
int n = int.Parse(Console.ReadLine()!);
string size = Console.ReadLine()!;
string[] CharSize = size.Split(' ');
List sizeList = new List();
for (int i = 0; i < n; i++)
{
sizeList.Add(int.Parse(CharSize[i]));
}
for (int i = 0; i < n; i++)
{
for (int j = i; j < n; j++)
{
if (sizeList[i] > sizeList[j])
{
int num = sizeList[i];
sizeList[i] = sizeList[j];
sizeList[j] = num;
}
}
}
int count = 0;
int nowSize = 0;
while (nowSize + sizeList[count] < l && count < n)
{
count++;
}
Console.WriteLine(count);
}
}