#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define PUTS(x) std::cout << (x) << endl;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)

vector<Int> IntsIn(int n) {
    auto v = vector<Int>(0);
    for (int i = 0; i < n; i++) {
        Int a;
        cin >> a;
        v.push_back(a);
    }
    return v;
}

int main() {
    Int n, m;
    cin >> n >> m;
    auto a = IntsIn(n);
    auto b = IntsIn(n);
    auto g = vector<vector<Int>>(n, vector<Int>());

    rep(i, m) {
        Int c, d;
        cin >> c >> d;
        c--;
        d--;
        g[c].push_back(d);
        g[d].push_back(c);
    }

    auto components = vector<set<Int>>();
    auto visited = vector<bool>(n, false);

    rep(i, n) {
        auto component = set<Int>();
        function<void(Int)> dfs = [&](Int index) {
            if (visited[index]) return;
            visited[index] = true;
            component.insert(index);
            for (auto nextIndex : g[index]) {
                dfs(nextIndex);
            }
        };
        dfs(i);
        if (component.size() > 0) {
            components.push_back(component);
        }
    }

    for (auto s : components) {
        Int A = 0;
        Int B = 0;
        for (auto i : s) {
            A += a[i];
            B += b[i];
        }
        if (A != B) {
            PUTS("No");
            exit(0);
        }
    }
    PUTS("Yes");
}

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll H,W;
ll A[505][505];
ll B[505][505];
struct edge{ll to,cost;};
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using PPP=pair<ll,PP>;
using Graph=vector<vector<edge>>;
static const ll INF=1000000000000000;
ll d[2][505][505];
void dijkstra(ll sx,ll sy){
  for(ll k=0;k<2;k++)
    for(ll i=0;i<H;i++)
      for(ll j=0;j<W;j++)d[k][i][j]=INF;d[0][sx][sy]=0;
    priority_queue<PPP,vector<PPP>,greater<PPP>>que;
    que.push(PPP(0,PP(0,P(sx,sy))));
    while(!que.empty()){
        PPP p=que.top();que.pop();
        ll D=p.first;ll t=p.second.first;ll X=p.second.second.first;
      ll Y=p.second.second.second;
        if(d[t][X][Y]<D)continue;
        if(Y+1<W){
        if(d[t][X][Y]+A[X][Y]<d[0][X][Y+1]){
  d[0][X][Y+1]=d[t][X][Y]+A[X][Y];
    PPP p;p.first=d[0][X][Y+1];p.second.first=0;p.second.second.first=X;
     p.second.second.second=Y+1;que.push(p);
        }
        }
      if(0<=Y-1){
      if(d[t][X][Y]+A[X][Y-1]<d[0][X][Y-1]){
  d[0][X][Y-1]=d[t][X][Y]+A[X][Y-1];
    PPP p;p.first=d[0][X][Y-1];p.second.first=0;p.second.second.first=X;
     p.second.second.second=Y-1;que.push(p);
        }
      
      
      }
      if(X+1<H){
      if(d[t][X][Y]+B[X][Y]<d[0][X+1][Y]){
  d[0][X+1][Y]=d[t][X][Y]+B[X][Y];
    PPP p;p.first=d[0][X+1][Y];p.second.first=0;p.second.second.first=X+1;
     p.second.second.second=Y;que.push(p);
        }
      
      }
      if(0<=H-1){
      if(d[t][X][Y]+2-t<d[1][X-1][Y]){
  d[1][X-1][Y]=d[t][X][Y]+2-t;
    PPP p;p.first=d[1][X-1][Y];p.second.first=1;p.second.second.first=X-1;
     p.second.second.second=Y;que.push(p);
        }
      
      }
    }
}
int main(){
  cin>>H>>W;Graph G(H*W);
  for(ll i=0;i<H;i++)
    for(ll j=0;j<W-1;j++)cin>>A[i][j];
  for(ll i=0;i<H-1;i++)
    for(ll j=0;j<W;j++)cin>>B[i][j];
  dijkstra(0,0);
 cout<<d[0][H-1][W-1]<<endl;
  return 0;
}