#include <bits/stdc++.h>
using namespace std;
int main() {
  int c, d, b1[105] = {0}, g1[105] = {0};
  cin >> c >> d;
  int b, g, x;
  cin >> b;
  for (int i = 0; i < b; i++) {
    cin >> x;
    b1[x] = 1;
  }
  cin >> g;
  for (int i = 0; i < g; i++) {
    cin >> x;
    g1[x] = 1;
  }
  for (int i = 0; i < 1000001; i++) {
    if (b1[i % c] == 1 || g1[i % d] == 1) {
      b1[i % c] = 1;
      g1[i % d] = 1;
    }
  }
  bool ab = true, ag = true;
  for (int i = 0; i < c; i++) {
    if (!b1[i]) {
      ab = false;
      break;
    }
  }
  for (int i = 0; i < d; i++) {
    if (!g1[i]) {
      ag = false;
      break;
    }
  }
  if (!ab || !ag) {
    cout << "No\n";
  } else {
    cout << "Yes\n";
  }
  return 0;
}
