#include <bits/stdc++.h>
using namespace std;
bool solve(vector<int> a, vector<int> b) {
  long long k = 1;
  int n = (int)a.size(), m = (int)b.size();
  bool sw = true;
  if ((a[0] == 1) || (b[0] == 1)) {
    a[0] = 1;
    b[0] = 1;
  }
  while (!((k % n) == 0 && (k % m) == 0) || sw) {
    if (((k % n) == 0) && ((k % m) == 0)) sw = false;
    if (a[k % n] == 1 || b[k % m] == 1) {
      if (a[k % n] == 0 || b[k % m] == 0) sw = true;
      a[k % n] = 1;
      b[k % m] = 1;
    }
    k++;
  }
  return ((find(a.begin(), a.end(), 0) == a.end()) &&
          (find(b.begin(), b.end(), 0) == b.end()));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  int bs, gs, x;
  vector<int> a, b;
  while (cin >> n >> m) {
    a.clear(), b.clear();
    a.assign(n, 0), b.assign(m, 0);
    cin >> bs;
    for (int i = 0; i < bs; ++i) {
      cin >> x;
      a[x] = 1;
    }
    cin >> gs;
    for (int i = 0; i < gs; ++i) {
      cin >> x;
      b[x] = 1;
    }
    if ((bs == 0) && (gs == 0))
      cout << "No" << endl;
    else {
      solve(a, b) ? cout << "Yes" : cout << "No";
      puts("");
    }
  }
  return 0;
}
