// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <atcoder/all>

using namespace std;
// using namespace atcoder;

// using ll = long long;
// int : -2**31 〜 2**31-1 (2**31=2147483648=2*10**9)
// long long : -2**63 〜 2**63-1 (2**63=9223372036854775808=9*10**18)

using P = pair<int,int>;

// #define int ll
// int main() --> signed main() として使う．

#define rep(i,n) for (int i=0; i<n; i++)
#define rep2(i,s,e) for (int i=s; i<e; i++)

template<class T> bool chmin(T &a, T b) {if(a>b){a=b;return 1;}return 0;}
// template<class T> bool chmax(T &a, T b) {if(a<b){a=b;return 1;}return 0;}

const int INF = (int)2e9;

struct Edge {
    int cost;
    int to;
    Edge(int c, int t) : cost(c), to(t) {}
};

void dijkstra_heap(int s, vector<vector<Edge>> &edges, vector<int> &dist) {
    dist[s] = 0;
    priority_queue<P,vector<P>,greater<P>> q;
    q.push(make_pair(dist[s],s));
    while (!q.empty()) {
        int v = q.top().second;
        int d = q.top().first;
        q.pop();
        if (d>dist[v]) continue;
        for (auto e: edges[v]) {
            if (chmin(dist[e.to],dist[v]+e.cost)) {
                q.push(make_pair(dist[e.to],e.to));
            }
        }
    }
}

int no(int i, int j, int C) {
        return i*C + j;
}

int main() {
    cin.tie(nullptr);
    // 小数点以下12桁まで
    cout << fixed << setprecision(12);
    // input
    int R,C;
    cin >> R >> C;
    vector<vector<int>> a(R,vector<int>(C-1));
    vector<vector<int>> b(R-1,vector<int>(C));
    vector<int> dist(R*C,INF);
    vector<vector<Edge>> edges(R*C);
    rep(i,R) rep(j,C-1) cin >> a[i][j];
    rep(i,R-1) rep(j,C) cin >> b[i][j];
    // edges
    rep(i,R) {
        rep(j,C) {
            // left
            if (j>0) edges[no(i,j,C)].push_back(Edge(a[i][j-1],no(i,j-1,C)));
            // right
            if (j<C-1) edges[no(i,j,C)].push_back(Edge(a[i][j],no(i,j+1,C)));
            // down
            if (i<R-1) edges[no(i,j,C)].push_back(Edge(b[i][j],no(i+1,j,C)));
            // up
            rep2(k,1,i+1) {
                edges[no(i,j,C)].push_back(Edge(1+k,no(i-k,j,C)));
            }
        }
    }
    // calc
    dijkstra_heap(no(0,0,C),edges,dist);
    // output
    // rep(i,R) {
    //     rep(j,C) {
    //         cout << dist[no(i,j,C)] << " ";
    //     }
    //     cout << endl;
    // }  
    int ans = dist[no(R-1,C-1,C)];
    cout << ans << endl;
}
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define endl '\n'
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define rev(a) a.rbegin(),a.rend()
#define all(a) a.begin(),a.end()
#define setbits(x) (__builtin_popcount(x))
#define pi pair<int,int>
#define precise(a,k) cout<<fixed<<setprecision(k)<<a;
#define fill(s,x,n) vector<s> x(n); rep(i,0,n) cin>>x[i];
#define minpq(type) priority_queue<type,vector<type>,greater<type>>
#define debug(...) cerr<<"{ "<<#__VA_ARGS__<<" = "<<(__VA_ARGS__)<<" }"<<endl;
#define debugp(...) cerr<<"{ "<<#__VA_ARGS__<<" = "<<"("<<(__VA_ARGS__).ff<<","<<(__VA_ARGS__).ss<<")"<<" }"<<endl;
#define debugv(...) cerr<<"{ "; for(int i=0; i<size(__VA_ARGS__); i++) cerr<<#__VA_ARGS__<<"["<<i<<"]"<<" = "<<(__VA_ARGS__)[i]<<" ; "; cerr<<"}"<<endl;
#define debugpv(...) cerr<<"{ "; for(int i=0; i<size(__VA_ARGS__); i++) cerr<<#__VA_ARGS__<<"["<<i<<"]"<<" = "<<"("<<(__VA_ARGS__)[i].ff<<","<<(__VA_ARGS__)[i].ss<<")"<<" ; "; cerr<<"}"<<endl;
#define mod 998244353
#define inf 1000000007
#define inf64  1000000000000000005
#define PI 3.141592653589793

void solve(){
    int n,m;
    cin>>n>>m;
    fill(int,a,m);
    if(m==0){
        cout<<1;
        return;
    }
    sort(all(a));
    vector<int> v;
    int t = 1;
    int prev = 0;
    for(int x: a){
        if(x-prev>1){
            v.push_back(x-prev-1);
            t+=x-prev;
        }
        prev = x;
    }
    if(n-prev>0){
        v.push_back(n-prev);
         t+=n-prev;
    }
   // debugv(v)
    if(v.size()<=1){
        cout<<v.size();
        return;
    }
    sort(all(v));
    int ans = 0;
    for(int i=0; i<(int)v.size(); i++){
        ans+=v[i]/v[0] + (bool)(v[i]%v[0]);
    }
    cout<<ans;
}

    
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout);  
    #endif
    */
    int test;
   // cin>>test;    
    test=1;
    //sieve();
    //int cse=1;
    while(test--){
       // cout<<"Case #"<<cse<<": ";
        solve();
        cout<<endl;
        //cse++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}