class Test
  def initialize(m, books)
    @m, @books = m, books
  end 

  def main
    l, r = 0, [1500000, @books.reduce { |v, x| v += x }].min

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

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

while true do
  m, s = STDIN.gets.split(' ').map { |x| x.to_i}

  break if [m, s] == [0, 0]

  books = []
  (1..s).each do |x| 
    books.push STDIN.gets.chomp.to_i
  end 

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