#include<bits/stdc++.h>
using namespace std;
 
typedef long long LL;         
typedef pair<int, int> P;
 
const int maxn = 500 + 10;        
const int M_MAX = 10 * maxn * maxn;
const int mod = 1e9 + 7;
const LL INF = 0x3f3f3f3f;    
const double eps = 1e-6;      

struct edge {
    int to, cost, next;
}e[5000010];

int n, m;
int h[1000010], d[1000010], len = 1;

int p(int x, int y) { return (x - 1) * m + y; }

void addedge(int v, int u, int cost) {
    e[len].to = u;
    e[len].cost = cost;
    e[len].next = h[v];
    h[v] = len++;
}

void solve() {
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j < m; j++) {
            int c; cin >> c;
            addedge(p(i, j) , p(i, j + 1), c);
            addedge(p(i,j+1), p(i, j), c);
        }
    }
    for(int i = 1; i < n; i++) {
        for(int j = 1; j <= m; j++) {
            int c; cin >> c;
            addedge(p(i, j), p(i+1, j), c);
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            addedge(p(i, j), p(i, j) + n*m, 1);
            addedge(p(i,j) + n*m, p(i,j), 0);
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            addedge(p(i+1, j) + n*m, p(i,j) + n*m, 1);
        }
    }
    for(int i = 1; i <= 2 * n * m; i++) d[i] = INF;
    d[1] = 0;
    priority_queue<P> que;
    que.emplace(make_pair(0, 1));
    while(!que.empty()) {
        P pe = que.top(); que.pop();
        int v = pe.second;
        if(-d[v] != pe.first) continue;
        for(int i = h[v]; i; i = e[i].next) {
            if(d[e[i].to] > e[i].cost + d[v]) {
                d[e[i].to] = e[i].cost + d[v];
                que.emplace(make_pair(-d[e[i].to], e[i].to));
            }
        }
    }
    cout << d[n*m] << endl;
}   
 
int main() {
    ios::sync_with_stdio(false);
    //srand(time(NULL));    //更新种子
    solve();
    return 0;
}  
#include <stdio.h>
inline int read() {
    int b = getchar(), c = 0;
    int m = b == 45;
    if (m) b = getchar();
    while (b > 47) {
        c = c * 10 + b - 48;
        b = getchar();
    }
    return m ? - c : c;
}
int p[200001];
int main() {
    int a[400002];
    int n = read(), m = read();
    long s = 0;
    for (int i = 1; i <= n + n; i++) a[i] = read();
    for (int i = 0; i < m + m; i++) p[read()] = 1;
    p[1] = 1;
    for (int i = 1; i < 200001; i++) {
        if (p[i]) s += a[i] - a[i + n];
    }
    puts(s ? "No" : "Yes");
}