#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define FASTIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 1000000007
#define nline “\n”
#define pb push_back
#define vvi vector<vector>
#define vvll vector<vector>
#define vi vector
#define vb vector
#define vll vector
#define pi pair<int,int>
#define pll pair<long long , long long>
#define read(p,q,arr) for(int i=p;i<q;++i) cin>>arr[i];
#define print(p,q,arr) for(int i=p;i<q;++i) cout<<arr[i]<<" ";
ll k , n , arr[20];
bool isPossible(ll mid){
ll painters = 1 ;
ll painted = 0 ;
for(int i = 0 ; i<n ; ++i){
if(painted+arr[i]>mid){
painters+=1;
painted = arr[i];
if(painters>k){
return false;
}
}else{
painters+=arr[i];
}
}
return true;
}
void solve(){
cin>>k>>n;
read(0,n,arr);
ll sum = 0 ;
sort(arr,arr+n);
for(int i = 0 ; i<n ; ++i) sum+=arr[i];
ll s = 0 ;
ll e = sum;
ll ans = INT_MAX;
while(s<=e){
ll mid = (s+e)/2 ;
if(isPossible(mid)){
ans = min(ans,mid);
e=mid-1;
}else{
s=mid+1;
}
}
cout<<ans<<nline;
}
int main() {
FASTIO
int t;
//cin>>t;
t=1;
while(t–){
solve();
}
}