#include <bits/stdc++.h>
using namespace std;
int n, m, a, b;
bool x[101];
bool y[101];
int main() {
  scanf("%d%d", &n, &m);
  memset(x, false, sizeof x);
  memset(y, false, sizeof y);
  scanf("%d", &b);
  for (int i = 0; i < b; i++) {
    scanf("%d", &a);
    x[a] = 1;
  }
  scanf("%d", &b);
  for (int i = 0; i < b; i++) {
    scanf("%d", &a);
    y[a] = 1;
  }
  for (int i = 0; i < n * m * 100; i++) {
    a = i % n;
    b = i % m;
    x[a] |= y[b];
    y[b] |= x[a];
  }
  for (int i = 0; i < n; i++)
    if (!x[i]) {
      puts("No");
      return 0;
    }
  for (int i = 0; i < m; i++)
    if (!y[i]) {
      puts("No");
      return 0;
    }
  puts("Yes");
  return 0;
}
