#include <bits/stdc++.h>
using namespace std;
set<long long> b, g;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  long long x;
  cin >> x;
  for (long long i = 1; i <= x; i++) {
    long long y;
    cin >> y;
    b.insert(y);
  }
  cin >> x;
  for (long long i = 1; i <= x; i++) {
    long long y;
    cin >> y;
    g.insert(y);
  }
  for (long long i = 0; i <= 1e6; i++) {
    long long bind = i % n;
    long long gind = i % m;
    if (b.find(bind) != b.end() || g.find(gind) != g.end()) {
      b.insert(bind);
      g.insert(gind);
    }
  }
  if (b.size() == n && g.size() == m) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }
  return 0;
}
