#include <bits/stdc++.h>
int boy[1005];
int girl[1005];
int main() {
  int m, n;
  scanf("%d%d", &n, &m);
  int p, q;
  scanf("%d", &p);
  for (int i = 0; i < p; i++) {
    int k;
    scanf("%d", &k);
    boy[k]++;
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int k;
    scanf("%d", &k);
    girl[k]++;
  }
  for (int i = 0; i < 100005; i++) {
    int b = i % n;
    int g = i % m;
    if (boy[b]) girl[g]++;
    if (girl[g]) boy[b]++;
  }
  int c = 1, d = 1;
  for (int i = 0; i < n; i++) {
    if (boy[i] == 0) c = 0;
  }
  for (int i = 0; i < m; i++) {
    if (girl[i] == 0) d = 0;
  }
  if (d == 0 || c == 0)
    printf("No");
  else
    printf("Yes");
}
