#include <bits/stdc++.h>
#define ll long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

const int N = 2e5+5;
ll bit[N], row[N], col[N];
vector<ll> tt[N];

void update(int pos, int val){
	while(pos < N){
		bit[pos] += val;
		pos += pos&-pos;
	}
}

int query(int pos){
	int res = 0;
	while(pos){
		res += bit[pos];
		pos -= pos&-pos;
	}
	return res;
}

signed main(){
	fastio
	ll h,w,m;
	cin >> h >> w >> m;
	fill(row,row+N,w);
	fill(col,col+N,h);
	while(m--){
		ll x,y;
		cin >> x >> y;
		x--,y--;
		row[x] = min(row[x],y);
		col[y] = min(col[y],x);
		tt[y].push_back(x);
	}
	ll ans = 0;
	for(ll i = 0;i < col[0];i++) ans += row[i];
	ll ok[h];
	fill(ok,ok+h,1);
	for(ll i=col[0];i < h;i++) ok[i] = 0, update(i,1);
	for(ll i = 0;i < row[0];i++){
		for(ll j : tt[i]){
			if(ok[j]) ok[j] = 0, update(j,1);
		}
		ans += query(col[i]-1);
	}
	cout << ans <<endl;;
}
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;

int f(int b,int r,int c){
  return b*500*500+r*500+c;
}

int main(){
  int R,C; cin >> R >> C;
  vvi g(500*500*2);
  vvi co(500*500*2);
  rep(r,R) rep(c,C-1){
    int in; cin >> in;
    g[f(0,r,c)].pb(f(0,r,c+1));
    g[f(0,r,c+1)].pb(f(0,r,c));
    co[f(0,r,c)].pb(in);
    co[f(0,r,c+1)].pb(in);
  }
  rep(r,R-1) rep(c,C){
    int in; cin >> in;
    g[f(0,r,c)].pb(f(0,r+1,c));
    co[f(0,r,c)].pb(in);
  }
  rep(r,R-1) rep(c,C){
    g[f(1,r+1,c)].pb(f(1,r,c));
    co[f(1,r+1,c)].pb(1);
  }
  rep(r,R) rep(c,C){
    g[f(0,r,c)].pb(f(1,r,c));
    co[f(0,r,c)].pb(1);
    g[f(1,r,c)].pb(f(0,r,c));
    co[f(1,r,c)].pb(0);
  }
  vector<int> D(500*500*2, -1);
  vector<bool> used(500*500*2, false);
  priority_queue<pair<int,int>,
                 vector<pair<int,int>>,
                 greater<pair<int,int>>> q;
  q.push({(int)0,f(0,0,0)});
  while(!q.empty()){
    int d = q.top().first; int to = q.top().second; q.pop();
    if(used[to]) continue;
    used[to] = true; D[to] = d;
    rep(i,sz(g[to])){
      int nxt=g[to][i];
      if(D[nxt] != -1 && D[nxt] <= D[to] + co[to][i]) continue;
      q.push({D[to] + co[to][i], nxt});
    }
  }

  int ans = D[f(0,R-1,C-1)];
  cout << ans << endl;
  return 0;
}
