#include <bits/stdc++.h>
using namespace std;
int n, m, boys, g;
int a[105], b[105];
int gcd(int x, int y) {
  if (!y) return x;
  if (!x) return y;
  return gcd(y, x % y);
}
int main() {
  scanf("%d %d", &n, &m);
  scanf("%d", &boys);
  for (int i = (0); i < (boys); ++i) {
    int id;
    scanf("%d", &id);
    a[id] = 1;
  }
  scanf("%d", &g);
  for (int i = (0); i < (g); ++i) {
    int id;
    scanf("%d", &id);
    b[id] = 1;
  }
  for (int d = (0); d < (n * m + 1); ++d) {
    int x = d % n;
    int y = d % m;
    if (a[x] || b[y]) a[x] = b[y] = 1;
  }
  if (gcd(n, m) == 1)
    puts("Yes");
  else {
    int h = 0;
    for (int i = (0); i < (n); ++i) h += a[i];
    for (int i = (0); i < (m); ++i) h += b[i];
    printf("%s\n", h == n + m ? "Yes" : "No");
  }
  return 0;
}
