#include<iostream>
using namespace std;

int main(){
    while(1){
        int m, n;
        cin >> m >> n;

        if(m + n == 0)  break;

        int w[n], sum = 0, minp = 1000001;
        for(int i = 0; i < n; i++){
            cin >> w[i];
            sum += w[i];
            minp = min(minp, w[i]); 
        }

        int l = minp, r = sum;

        while(r-l > 0){
            int mid = (r+l) / 2;

            int tmpm = 1, nowp = 0;
            for(int i = 0; i < n; i++){
                if(nowp + w[i] <= mid){
                    nowp += w[i];
                }else{
                    nowp = w[i];
                    tmpm++;
                }
            }

            if(tmpm <= m)   r = mid;
            else            l = mid+1;
        }

        cout << r << endl;
    }

    return 0;
}
