#include <bits/stdc++.h>
using namespace std;
bool v[105];
int gcd(int a, int b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
int main() {
  int n, m, b, f, i, g, x;
  cin >> n >> m;
  g = gcd(n, m);
  cin >> b;
  for (i = 1; i <= b; i++) {
    cin >> x;
    v[x % g] = 1;
  }
  cin >> f;
  for (i = 1; i <= f; i++) {
    cin >> x;
    v[x % g] = 1;
  }
  for (i = 0; i < g; i++) {
    if (v[i] == 0) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}
