#include <bits/stdc++.h>
using namespace std;
const int inf = 1e5;
void debug(int n, ...) {
  va_list v1;
  va_start(v1, n);
  for (int i = 0; i < n; i++) {
    int val = va_arg(v1, int);
    printf("%d ", val);
  }
  va_end(v1);
  printf("\n");
}
const int TURN = 1e7;
const int N = 107;
bool e[N];
bool k[N];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int hb, hg;
  scanf("%d", &hb);
  for (int i = 0; i < hb; i++) {
    int b;
    scanf("%d", &b);
    e[b] = 1;
  }
  scanf("%d", &hg);
  for (int i = 0; i < hg; i++) {
    int g;
    scanf("%d", &g);
    k[g] = 1;
  }
  for (int i = 0; i < TURN; i++) {
    if (e[i % n] || k[i % m]) {
      e[i % n] = 1;
      k[i % m] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (!e[i]) {
      printf("NO");
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    if (!k[i]) {
      printf("NO");
      return 0;
    }
  }
  printf("YES");
  return 0;
}
