#include <bits/stdc++.h>
using namespace std;
int N, M, B, G;
bool hb[102];
bool hg[102];
int unb, ung;
int main() {
  int n;
  bool res = false;
  memset(hb, 0, sizeof(hb));
  memset(hg, 0, sizeof(hg));
  scanf("%d%d", &N, &M);
  unb = N;
  ung = M;
  scanf("%d", &B);
  for (int i = 0; i < B; i++) {
    scanf("%d", &n);
    hb[n] = true;
    unb--;
  }
  scanf("%d", &G);
  for (int i = 0; i < G; i++) {
    scanf("%d", &n);
    hg[n] = true;
    ung--;
  }
  int maxopt = 100005;
  for (int i = 0; i < maxopt; i++) {
    int b = i % N;
    int g = i % M;
    if (!hb[b] && hg[g]) {
      unb--;
      hb[b] = true;
    } else if (hb[b] && !hg[g]) {
      ung--;
      hg[g] = true;
    }
    if (unb == 0 && ung == 0) {
      res = true;
      break;
    }
  }
  if (res)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}
