using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush =
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}
		public void Solve(ConsoleInput cin) {
			while(true) {
				var m = cin.ReadInt;
				var n = cin.ReadInt;
				if(m == 0 && n == 0) break;
				var W = cin.ReadIntArray(n);
				var left = W.Max();
				var right = W.Sum() + 1;
				//$y is in [left, right]
				while(left < right) {
					var mid = (left + right) / 2;	//mid<right
					var canAccomodate = true;
					var floor = 1;
					var occupy = 0;
					for(int i = 0; i < n; i++) {
						occupy += W[i];
						if(occupy <= mid)
							continue;
						floor++;
						occupy = W[i];
						if(floor > m) {
							canAccomodate = false;
							break;
						}
					}
					if(canAccomodate) {
						right = mid;
					} else {
						left = mid + 1;
					}
				}
				Console.WriteLine(left);
			}
		}

	}
	static class ExtendClass {
		public static void Swap<T>(this T[] A, int x, int y) {
			var tmp = A[x];
			A[x] = A[y];
			A[y] = tmp;
		}
		public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);
		//http://baba-s.hatenablog.com/entry/2017/12/21/104600
		public static IEnumerable<IEnumerable<T>> Chunks<T>(this IEnumerable<T> self, int size) {
			while(self.Any()) {
				yield return self.Take(size);
				self = self.Skip(size);
			}
		}
		public static IEnumerable<T> MinBy<T, U>(this IEnumerable<T> source, Func<T, U> selector) {
			return SelectBy(source, selector, (a, b) => Comparer<U>.Default.Compare(a, b) < 0);
		}

		public static IEnumerable<T> MaxBy<T, U>(this IEnumerable<T> source, Func<T, U> selector) {
			return SelectBy(source, selector, (a, b) => Comparer<U>.Default.Compare(a, b) > 0);
		}

		private static IEnumerable<T> SelectBy<T, U>(IEnumerable<T> source, Func<T, U> selector, Func<U, U, bool> comparer) {
			var list = new LinkedList<T>();
			U prevKey = default(U);
			foreach(var item in source) {
				var key = selector(item);
				if(list.Count == 0 || comparer(key, prevKey)) {
					list.Clear();
					list.AddLast(item);
					prevKey = key;
				} else if(Comparer<U>.Default.Compare(key, prevKey) == 0) {
					list.AddLast(item);
				}
			}
			return list;
		}
	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator = separator;
			this._stream = stream;
			inputStream = new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count != 0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i < tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i < N; ++i)
				ret[i] = Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek() == -1; }
		}
	}

}



Measured memory_bytes: 14564