require'prime'
a=Prime.take(100000)
def g;gets.split.map &:to_i;end
def f x,y,c,o
  o-=1
  (n=$l[y][x])>0?(o+=n):(c-=n)
  o>$m&&o=$m
  if c>$z||c>$f||o==0
    nil
  elsif y==$h-1
    $z>c&&$z=c
    c
  else
    [f(x-1,y,c,o),f(x+1,y,c,o),f(x,y+1,c,o)].compact.min
  end
end
while(w,$h=g;w>0)
$z=1e9
$f,$m,o=g
$l=(1..$h).map{g<<-1e9}
puts (0...w).map{|i|f(i,0,0,o)}.compact.min||"NA"
end