#include <bits/stdc++.h>
using namespace std;

int main() {
  for(int m, n; cin >> m >> n && (m|n);) {
    vector<int> a(n);
    for(int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    int l = *min_element(a.begin(), a.end()) , r = 1500001;
    while(r-l > 1) {
      int mid = (l+r)/2;
      int x = 0, y = 1;
      for(int i = 0; i < n; ++i) {
        if(x + a[i] > mid) {
          x = a[i];
          ++y;
        } else {
          x += a[i];
        }
      }
      if(y <= m) {
        r = mid;
      } else {
        l = mid+1;
      }
    }
    cout << l << endl;
  }
  return 0;
}