#include <iostream>
#include <vector>

using namespace std;
int main()
{
    while(true){
        int m, i;
        int low = 1, high = 1500000, mid;
        int N = 0;
        cin >> m;
        cin >> i;
        
        if( i == 0 )
            break;
        
        vector<int> a(i);
        
        for(int j = 0 ; j < i ; j++)
            cin >> a[j];
        
        while(true){
            mid = ( low + high ) / 2;
            int l = 0;
            bool que = false;
            
            for(int k = 0 ; k < m ; k++){
                int tot = 0;
                
                while(true){
                    if( mid >= tot + a[l] ){
                        tot = tot + a[l];
                        if( l< i - 1 )
                            l++;
                        else{
                            que = true;
                            break;
                        }
                    }
                    else
                        break;
                }
                
                if( que == true )
                    break;
            }
            
            if( que == true )
                high = mid;
            else
                low = mid + 1;
            
            if( low == high ){
                N = low;
                break;
            }
        }
        
        cout << N <<endl;
    }
}