class Test
  def initialize(m, books)
    @m, @books = m, books
    @li = @books.count - 1
  end 

  def main
    l, r = 0, [1_500_000, @books.reduce(:+)].min

    while r - l > 1 do
      m = (r + l) / 2 
      check(m) ? r = m : l = m
    end 
    r   
  end 

  def check(v)
    idx = 0 
    @m.times.each do
      vv = v 
      while vv > 0 do
        vv -= @books[idx]
        next if vv < 0 
        return true if idx == @li
        idx += 1
      end 
    end 
    false
  end 
end

loop do
  m, s = STDIN.gets.split(' ').map(&:to_i)
  break if [m, s] == [0, 0]

  books = s.times.map { STDIN.gets.to_i }

  puts Test.new(m, books).main
end