#include <bits/stdc++.h>

using namespace std;
ifstream f1("EXPLORE.inp");
ofstream f2("EXPLORE.out");
long int a[60000];
int main() {
	long int t,n,i,tong=0,d=0,tg,j;
	f1>>t>>n;
	for (i=1;i<=n;i++) 
	{f1>>a[i];
	}
	for (i=1;i<=n;i++)
	{for(j=i+1;j<=n;j++)
	 if (abs(a[i])>abs(a[j]))
	   { tg=a[i]; a[i]=a[j]; a[j]=tg;
	   }}
	   for (i=1;i<=n;i++)
	    {tong=tong+abs(a[i]); d++;
	     if (tong>t) break;
		}
		f2<<d-1;
	 
	   
	return 0;
}
