#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int b;
  cin >> b;
  vector<bool> x(n, false);
  for (int i = 0; i < b; i++) {
    int temp;
    cin >> temp;
    x[temp] = true;
  }
  int g;
  cin >> g;
  vector<bool> y(m, false);
  for (int i = 0; i < g; i++) {
    int temp;
    cin >> temp;
    y[temp] = true;
  }
  int day = 0;
  bool changed = false;
  while (true) {
    if (day % n == 0 && day % m == 0 && day != 0) {
      if (changed) {
        changed = false;
      } else {
        break;
      }
    }
    if (x[day % n] || y[day % m]) {
      if (x[day % n] == false) {
        x[day % n] = true;
        b++;
        changed = true;
      } else if (y[day % m] == false) {
        y[day % m] = true;
        g++;
        changed = true;
      }
    }
    day++;
  }
  if (b == n && g == m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
