#include<stdio.h>
int main() {
int n, m;
int i = 0, j = 0;
int flag = 0;
int a[10][10] = {0};
int b[10][10] = {0};
scanf("%d %d", &n, &m);
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
scanf("%d ", &a[i][j]);
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
scanf("%d ", &b[i][j]);
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (a[i][j] == b[i][j])
flag++; //判断有几个相同
}
}
if (flag == m * n) //如果每个都相同的话
printf("Yes\n");
else
printf("No\n");
}