#include <iostream>

using namespace std;

int m;
int n;
int a[128];

bool check(int x) {
  int sum = 0;
  int cnt = 1;

  for (int i = 0; i < n; i++) {
    if (a[i] > x)
      return false;
    sum += a[i];
    if (sum > x) {
      ++cnt;
      sum = a[i];
    }
  }
  
  return cnt <= m;
}

int solve() {

  int lo = 0;
  int hi = 1500000;

  while (hi - lo > 1) {
    int mi = (lo + hi) / 2;
    if (check(mi))
      hi = mi;
    else
      lo = mi;
  }

  return hi;
}


int main(int argc, char *argv[])
{
  while (1) {
    cin >> m >> n;
    if (!n && !m)
      break;
    for (int i = 0; i < n; i++)
      cin >> a[i];
    cout << solve() << endl;
  }
  return 0;
}