#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
const ld pi = acos(-1);
const ll inf = 1e18, mod = 1e9 + 7;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const ll N = 2e5 + 100;
void test_case() {
  long long int n, m;
  cin >> n >> m;
  bitset<101> boy(0);
  long long int b;
  cin >> b;
  for (long long int i = 0; i < (b - 1 + 1); i++) {
    long long int x;
    cin >> x;
    boy[x] = 1;
  }
  bitset<101> girl(0);
  long long int g;
  cin >> g;
  for (long long int i = 0; i < (g - 1 + 1); i++) {
    long long int x;
    cin >> x;
    girl[x] = 1;
  }
  long long int p = max(n, m);
  for (long long int i = 0; i < (p * p + 1); i++) {
    for (long long int j = 0; j < (m - 1 + 1); j++) {
      long long int k = m * i + j;
      boy[k % n] = boy[k % n] | girl[k % m];
      girl[k % m] = boy[k % n] | girl[k % m];
    }
  }
  boy = boy | girl;
  for (long long int i = 0; i < (max(n, m) - 1 + 1); i++) {
    if (boy[i] == 0) {
      cout << "NO" << endl;
      return;
    }
  }
  cout << "YES" << endl;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  ll tt = 1;
  while (tt--) {
    test_case();
  }
  return 0;
}
