
MAX = 2 ** 31

def memoize(h, w, o, f, val)
  $memo[h] ||= {}
  $memo[h][w] = {} unless $memo[h].key? w
  $memo[h][w][o] = {} unless $memo[h][w].key? o
  return $memo[h][w][o][f] if ($memo[h][w][o].key? f)
  return $memo[h][w][o][f] = val
end

def solve(h, w, o, f, direction, hl, wl, fl, ml, field)
  minimum = MAX
  o_new = o - 1
  return minimum if f > fl or o_new < 0
  return minimum if w < 0 or h > (hl + 1) or w > wl
  if h == (hl + 1) then
    return f
  end
  if field[h][w] < 0 then
    # ????????????????????´???
    minimum = [solve(h+1, w,   o_new, f-field[h][w], :bottom, hl, wl, fl, ml, field), minimum].min
    minimum = [solve(h,   w-1, o_new, f-field[h][w], :left,  hl, wl, fl, ml, field), minimum].min if direction != :right
    minimum = [solve(h,   w+1, o_new, f-field[h][w], :right, hl, wl, fl, ml, field), minimum].min if direction != :left
  else
    oxy = ((o_new+field[h][w]) > ml) ? ml : (o_new+field[h][w])
    # ????????????????´??????´???
    minimum = [solve(h+1, w,   oxy, f, :bottom, hl, wl, fl, ml, field), minimum].min
    minimum = [solve(h,   w-1, oxy, f, :left,   hl, wl, fl, ml, field), minimum].min if direction != :right
    minimum = [solve(h,   w+1, oxy, f, :right,  hl, wl, fl, ml, field), minimum].min if direction != :left
  end
  return memoize(h, w, o, f, minimum)
end

def gets_ints
  gets.split(" ").map(&:to_i)
end

loop do
  $memo = {}
  wl, hl = gets_ints
  break if wl == 0 and hl == 0
  fl, ml, ol = gets_ints
  field = (0...hl).map { gets_ints }
  ans = (0...wl).map do |w|
    solve(0, w, ol, 0, :bottom, hl-1, wl-1, fl, ml, field)
  end.min
  puts ans == MAX ? 'NA' : ans
end