#include <iostream>
#define MAX 1500000
using namespace std;

int main(){

  int n, m;
  while(cin >> m >> n, m||n){
    int d[101];
    for(int i = 0; i < n; i++) cin >> d[i];

    int l = 0, r = MAX;
    while(l < r){
      int mid = (l + r) / 2;
      bool judge = true;
      int sum = 0, cnt = 1;
      for(int i = 0; i < n; i++){
        if(sum + d[i] <= mid) sum += d[i];
        else {
          sum = d[i]; cnt++;
          if(sum > mid || cnt > m){
            judge = false; break;
          }
        }
      }
      if(judge) r = mid;
      else l = mid + 1;
    }
    cout << l << endl;
  }

}