#include <bits/stdc++.h>
using namespace std;
int marcg[112], marcb[112], n, m, b, g, xi;
int main() {
  scanf("%d %d", &n, &m);
  scanf("%d", &b);
  for (int i = 0; i < b; i++) {
    scanf("%d", &xi);
    marcb[xi] = 1;
  }
  scanf("%d", &g);
  for (int i = 0; i < g; i++) {
    scanf("%d", &xi);
    marcg[xi] = 1;
  }
  int mud = 1;
  while (mud != 0) {
    mud = 0;
    for (int i = 0; i < n * m; i++) {
      if (marcg[i % m] == marcb[i % n]) continue;
      marcg[i % m] = 1;
      marcb[i % n] = 1;
      mud = 1;
    }
  }
  int ok = 0;
  for (int i = 0; i < m; i++) {
    if (marcg[i] == 0) ok = 1;
  }
  if (ok != 0) {
    printf("No\n");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (marcb[i] == 0) ok = 1;
  }
  if (ok != 0) {
    printf("No\n");
    return 0;
  }
  printf("Yes\n");
}
