#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> inline bool chmin(T &a, const T &b){ return a > b && (a = b, true); }
template<class T> inline bool chmax(T &a, const T &b){ return a < b && (a = b, true); }

template <class K, class V>
class RadixHeap {
    static constexpr int bit_length = sizeof(K)*8;
    K last;
    size_t sz, cnt;
    array<vector<pair<K, V>>, bit_length> v;
    static inline int bsr(int x){
        return x ? bit_length-__builtin_clz(x) : 0;
    }
    static inline int bsr(ll x){
        return x ? bit_length-__builtin_clzll(x) : 0;
    }

    void pull() {
        if(cnt < v[0].size()) return;;
        int i = 1;
        while(v[i].empty()) i++;
        last = min_element(v[i].begin(),v[i].end())->first;
        for (auto &&x : v[i]) v[bsr(x.first ^ last)].push_back(x);
        v[i].clear();
    }
public:
    RadixHeap() : last(0), sz(0), cnt(0) {}
    void emplace(K x, V val){
        sz++;
        v[bsr(x^last)].emplace_back(x, val);
    }

    pair<K, V> top() {
        pull();
        return v[0][cnt];
    }

    void pop() {
        pull();
        sz--;
        cnt++;
    }

    size_t size() const { return sz; }
    bool empty() const { return !sz; }
};

void solve(int w, int h){
    int f, m, o;
    cin >> f >> m >> o;
    auto dp = make_v(h, w, w, w, m+1, INF<int>); // i, j, l, r, O;
    auto v = make_v(h, w, 0);
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> v[i][j];
        }
    }
    if(o <= 1) {
        puts("NA");
        return;
    }
    using P = tuple<int, int, int, int, int>;
    RadixHeap<int, P> Q;
    for (int i = 0; i < w; ++i) {
        dp[0][i][i][i][min(m, o+max(0, v[0][i])-1)] = max(0, -v[0][i]);
        Q.emplace(max(0, -v[0][i]), P{0, i, i, i, min(m, o+max(0, v[0][i])-1)});
    }
    while(!Q.empty()){
        int a, b, c, d, e; int cost;  tuple<int, int, int, int, int> A;
        tie(cost, A) = Q.top(); Q.pop();
        tie(a, b, c, d, e) = A;
        if(dp[a][b][c][d][e] < cost) continue;
        if(e <= 1) continue;
        if(a+1 < h){
            int ccost = cost + max(0, -v[a+1][b]);
            int ee = min(m, e-1+max(0, v[a+1][b]));
            if(chmin(dp[a+1][b][b][b][ee], ccost)){
                Q.emplace(ccost, P{a+1, b, b, b, ee});
            }
        }
        if(b){
            int ccost = cost + (b == c ? max(0, -v[a][b-1]) : 0);
            int ee = min(m, e-1+(b == c ? max(0, v[a][b-1]) : 0));
            if(chmin(dp[a][b-1][min(c, b-1)][d][ee], ccost)){
                Q.emplace(ccost, P{a, b-1, min(c, b-1), d, ee});
            }
        }
        if(b != w-1){
            int ccost = cost + (b == d ? max(0, -v[a][b+1]) : 0);
            int ee = min(m, e-1+(b == d ? max(0, v[a][b+1]) : 0));
            if(chmin(dp[a][b+1][c][max(d, b+1)][ee], ccost)){
                Q.emplace(ccost, P{a, b+1, c, max(d, b+1), ee});
            }
        }
    }
    int ans = INF<int>;
    for (int i = 0; i < w; ++i) {
        for (int j = 0; j < w; ++j) {
            for (int k = 0; k < w; ++k) {
                for (int l = 1; l <= m; ++l) {
                    chmin(ans, dp.back()[i][j][k][l]);
                }
            }
        }
    }
    if(ans >= f) puts("NA");
    else cout << ans << "\n";
}

int main() {
    int w, h;
    while(cin >> w >> h, w){
        solve(w, h);
    }
    return 0;
}


Measured memory_bytes: 7000