#include <bits/stdc++.h>
using namespace std;
bool hb[100], hg[100];
int main() {
  int b, g;
  cin >> b >> g;
  int h;
  cin >> h;
  while (h--) {
    int a;
    cin >> a;
    hb[a] = 1;
  }
  cin >> h;
  while (h--) {
    int a;
    cin >> a;
    hg[a] = 1;
  }
  for (int i = 0; i <= 1000000; i++) {
    int tb = i % b;
    int tg = i % g;
    if (hb[tb] == 1 || hg[tg] == 1) {
      hb[tb] = 1;
      hg[tg] = 1;
    }
  }
  int res = 0;
  for (int i = 0; i < b; i++) {
    if (hb[i] == 1) res++;
  }
  for (int i = 0; i < g; i++) {
    if (hg[i] == 1) res++;
  }
  if (res == b + g) {
    cout << "YES";
  } else
    cout << "NO";
}
