#include <stdio.h>

int main() {
    int n, m, flag = 1;
    scanf("%d %d", &n, &m);
    int arr1[n][m], arr2[n][m];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf("%d", &arr1[i][j]);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf("%d", &arr2[i][j]);
            if (arr2[i][j] != arr1[i][j]) {
                flag = 0;
            }
        }
    }
    if (flag == 1) printf("Yes\n");
    else printf("No\n");
    return 0;
}