#include <bits/stdc++.h>
using namespace std;
int n, m, b, g, x;
bool boy[101], gir[101];
bool flag = false;
int main() {
  memset(boy, false, sizeof(boy));
  memset(gir, false, sizeof(gir));
  scanf("%d %d", &n, &m);
  scanf("%d", &b);
  for (int i = 0; i < b; i++) {
    scanf("%d", &x);
    boy[x] = true;
  }
  scanf("%d", &g);
  for (int i = 0; i < g; i++) {
    scanf("%d", &x);
    gir[x] = true;
  }
  for (int i = 0; i < 1000000; i++) {
    if (b == n && g == m) {
      flag = true;
      break;
    }
    if (boy[i % n] == true && gir[i % m] == false) {
      g++;
      gir[i % m] = true;
    } else if (gir[i % m] == true && boy[i % n] == false) {
      b++;
      boy[i % n] = true;
    }
  }
  if (flag)
    printf("Yes");
  else
    printf("No");
  return 0;
}
