#include<bits/stdc++.h>
using namespace std;
int w,n,cnt,a[30005],ship[30005];
bool cmp(int a,int b){return a>b;}
void heap1(int x){
if(x==1)return;
int father=x/2;
if(ship[x]>ship[father])
swap(ship[x],ship[father]);
heap1(father);
}
void heap2(int x){
int child=x*2;
if(child>cnt)return ;
if(child+1<=cnt&&ship[child]<ship[child+1])child++;
if(ship[x]<ship[child]){
swap(ship[x],ship[child]);
heap2(child);
}
}
int main(){
cin>>w>>n;
fill(ship+1,ship+1+n,w);
for(int i=1;i<=n;i++)cin>>a[i];
sort(a+1,a+n+1,cmp);
int i=0;cnt=1;
while(i<n){
i++;
if(ship[1]>=a[i]){
if(ship[1]!=w)ship[1]=0;
else ship[1]-=a[i];
heap2(1);
}
else {
cnt++;
ship[cnt]-=a[i];
heap1(cnt);
}
}
cout<<cnt<<endl;
return 0;
}