
MAX = 2 ** 31

def solve(h, w, o, direction, hl, wl, fl, ml, field)
  $memo[h] ||= {}
  $memo[h][w] = {} unless $memo[h].key? w
  return $memo[h][w][o] if $memo[h][w].key? o
  minimum = MAX
  o_new = o - 1
  return minimum if w < 0 or h > (hl + 1) or w > wl
  return minimum if o_new < 0
  if h == (hl + 1) then    
    # p "h:#{h}, w:#{w}, o:#{o}, direction:#{direction}"
    return 0
  end
  if field[h][w] < 0 then
    # ????????????????????´???
    minimum = [solve(h+1, w,   o_new, :bottom, hl, wl, fl, ml, field), minimum].min
    minimum = [solve(h,   w-1, o_new, :left,   hl, wl, fl, ml, field), minimum].min if direction != :right
    minimum = [solve(h,   w+1, o_new, :right,  hl, wl, fl, ml, field), minimum].min if direction != :left
    minimum -= field[h][w]
  else
    oxy = ((o_new+field[h][w]) > ml) ? ml : (o_new+field[h][w])
    # ????????????????´??????´???
    minimum = [solve(h+1, w,   oxy, :bottom, hl, wl, fl, ml, field), minimum].min
    minimum = [solve(h,   w-1, oxy, :left,   hl, wl, fl, ml, field), minimum].min if direction != :right
    minimum = [solve(h,   w+1, oxy, :right,  hl, wl, fl, ml, field), minimum].min if direction != :left
  end
  return MAX if minimum > fl
  return $memo[h][w][o] = 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, :bottom, hl-1, wl-1, fl, ml, field)
  end.min
  puts ans == MAX ? 'NA' : ans
end