#include <bits/stdc++.h>
int n, x, y, a[1000], b[1000], now, m;
bool f1[1000], f2[1000];
int main() {
  int xx, yy;
  scanf("%d%d", &n, &m);
  scanf("%d", &x);
  for (int i = 1; i <= x; i++) {
    scanf("%d", &xx);
    f1[xx] = true;
  }
  scanf("%d", &y);
  for (int i = 1; i <= y; i++) {
    scanf("%d", &yy);
    f2[yy] = true;
  }
  now = n + m - x - y;
  int k;
  k = 0;
  while ((now > 0) && (k <= 10000)) {
    if ((f1[k % n]) && (!f2[k % m])) {
      f2[k % m] = true;
      now--;
    }
    if ((!f1[k % n]) && (f2[k % m])) {
      f1[k % n] = true;
      now--;
    }
    k++;
  }
  if (now == 0)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}
