class Array
	def bsearch_first_index(l = 0, r = size - 1, &pred)
		return nil if l > r
		c = (l + r) / 2 
		if pred[self[c]]
			bsearch_first_index(l, c-1, &pred) || c
		else
			bsearch_first_index(c+1, r, &pred)
		end
	end

	def bsearch_first_item(l = 0, r = size - 1, &pred)
		i = bsearch_first_index(l, r, &pred)
		i ? self[i] : nil
	end

	def bsearch_last_index(l = 0, r = size - 1, &pred)
		return nil if l > r
		c = (l + r) / 2 
		if pred[self[c]]
			bsearch_last_index(c+1, r, &pred) || c
		else
			bsearch_last_index(l, c-1, &pred)
		end
	end

	def bsearch_last_item(l = 0, r = size - 1, &pred)
		i = bsearch_last_index(l, r, &pred)
		i ? self[i] : nil
	end
end

def f(books, sw)
	d = 1
	rest = sw
	books.each do |bw|
		return Float::INFINITY if bw > sw
		if rest < bw
			d += 1
			rest = sw - bw
		else
			rest -= bw
		end
	end
	d
end

loop do
	m, n = gets.split.map &:to_i
	break if m == 0
	books = (1..n).map {gets.to_i}
	p (0..books.inject(:+)).to_a.bsearch_first_index{|sw| f(books, sw) <= m}
end