#include<iostream>
#include<algorithm>
#include<vector>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
vector<int> G;
int m;

bool check(int v)
{
  int cnt = 0;
  int sum = 0;
  rep(i,G.size())
    {
      if(G[i] > v)return false;
      sum += G[i];
      if(sum > v)
	{
	  sum = G[i];
	  cnt++;
	}
    }
  return cnt < m;
}

int main()
{
  int n;
  while(cin >> m >> n,m|n)
    {
      G.resize(n);
      rep(i,n)cin >> G[i];
      //check(1799);
      //return 0;
      int L = 0;
      int R = 1500000;
      int M;
      rep(j,100)
	{
	  M = (L+R)/2;
	  if(!check(M))
	    L = M;
	  else
	    R = M;	      
	}
      cout << R << endl; 
    }
  return 0;
}