#include <bits/stdc++.h>
using namespace std;
void zero(bool a[], int n) {
  for (int i = 0; i < n; ++i) {
    a[i] = false;
  }
}
int main(int argc, char *argv[]) {
  int n, m;
  scanf("%d%d", &n, &m);
  bool man[n], woman[m];
  zero(man, n);
  zero(woman, m);
  int b;
  scanf("%d", &b);
  for (int i = 0; i < b; ++i) {
    int num;
    scanf("%d", &num);
    man[num] = true;
  }
  scanf("%d", &b);
  for (int i = 0; i < b; ++i) {
    int num;
    scanf("%d", &num);
    woman[num] = true;
  }
  for (int i = 0; i < n * m * max(n, m); ++i) {
    if (man[i % n] || woman[i % m]) {
      man[i % n] = true;
      woman[i % m] = true;
    }
  }
  for (int i = 0; i < n; ++i) {
    if (!man[i]) {
      cout << "NO";
      return 0;
    }
  }
  for (int i = 0; i < m; ++i) {
    if (!woman[i]) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
