#include <bits/stdc++.h>
using namespace std;
class customIO {
 public:
  istream& in;
  ostream& out;
  customIO(istream& _in, ostream& _out) : in(_in), out(_out) {}
  string next() {
    string s;
    in >> s;
    return s;
  }
  double nextDouble() { return stod(next()); }
  int nextInt() { return stoi(next()); }
  long long nextLong() { return stoll(next()); }
  template <typename T>
  void print(T t) {
    out << t;
  }
  template <typename T, typename... U>
  void print(T t, U... u) {
    out << t;
    print(u...);
  }
  template <typename T, typename... U>
  void println(T t, U... u) {
    print(t, u..., "\n");
  }
  void println() { print("\n"); }
};
int diff[505][505];
class CF1119C {
 public:
  void solve(customIO& io) {
    int n = io.nextInt();
    int m = io.nextInt();
    vector<vector<int> > a, b;
    for (int i = 0; i < n; ++i) {
      vector<int> cur;
      for (int j = 0; j < m; ++j) {
        cur.push_back(io.nextInt());
      }
      a.push_back(cur);
    }
    for (int i = 0; i < n; ++i) {
      vector<int> cur;
      for (int j = 0; j < m; ++j) {
        cur.push_back(io.nextInt());
      }
      b.push_back(cur);
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (a[i][j] != b[i][j]) ++diff[i][j];
      }
    }
    for (int i = 0; i < n; ++i) {
      int c = 0;
      for (int j = 0; j < m; ++j) {
        c += diff[i][j];
      }
      if (c % 2 == 1) {
        io.println("No");
        return;
      }
    }
    for (int i = 0; i < m; ++i) {
      int c = 0;
      for (int j = 0; j < n; ++j) {
        c += diff[j][i];
      }
      if (c % 2 == 1) {
        io.println("No");
        return;
      }
    }
    io.println("Yes");
    return;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << fixed;
  cout.precision(20);
  istream& in(std::cin);
  ostream& out(std::cout);
  customIO io(in, out);
  CF1119C solver;
  solver.solve(io);
  return 0;
}
