#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int m, n;
int w[110];

bool check(int mid) {
  int sum = 0, res = 1;
  for (int i = 0; i < n; i++) {
    if (w[i] > mid) return false;
    if (sum + w[i] > mid) sum = w[i], res++;
    else sum += w[i];
  }
  return res <= m;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  while (cin >> m >> n, m) {
    for (int i = 0; i < n; i++) {
      cin >> w[i];
    }
    int ng = 0, ok = 1500000;
    while (ok - ng > 1) {
      int mid = (ng + ok) / 2;
      if (check(mid)) ok = mid;
      else ng = mid;
    }
    cout << ok << endl;
  }

  return 0;
}
