#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, dema, demb, x, y;
  int a[101], b[101];
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  scanf("%d%d", &n, &m);
  scanf("%d", &dema);
  for (int i = 1; i <= dema; i++) {
    scanf("%d", &x);
    a[x] = 1;
  }
  scanf("%d", &demb);
  for (int i = 1; i <= demb; i++) {
    scanf("%d", &x);
    b[x] = 1;
  }
  for (int i = 1; i <= 1000000; i++) {
    x = i % n;
    y = i % m;
    if (a[x] + b[y] != 0) {
      if (a[x] == 0) {
        a[x] = 1;
        dema++;
      }
      if (b[y] == 0) {
        b[y] = 1;
        demb++;
      }
    }
  }
  if (dema == n && demb == m)
    printf("Yes");
  else
    printf("No");
}
