#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  int c, d;
  d = max(a, b);
  c = min(a, b);
  if (d % c == 0)
    return c;
  else
    return gcd(d % c, c);
}
int pep[101];
int main() {
  int n, m, b, g, c, i, cnt = 0, id;
  memset(pep, 0, sizeof(pep));
  cin >> n >> m;
  c = gcd(n, m);
  cin >> b;
  for (i = 0; i < b; i++) {
    cin >> id;
    if (!pep[id % c]) pep[id % c] = 1, cnt++;
  }
  cin >> g;
  for (i = 0; i < g; i++) {
    cin >> id;
    if (!pep[id % c]) pep[id % c] = 1, cnt++;
  }
  if (cnt == c)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}
