#include <bits/stdc++.h>
using namespace std;
int main() {
  int b[110], g[110], n, m, numn, numm, na, ma, i, p;
  while (cin >> n >> m) {
    numn = n;
    numm = m;
    memset(b, 0, sizeof(b));
    memset(g, 0, sizeof(g));
    cin >> na;
    for (i = 0; i < na; i++) {
      cin >> p;
      b[p] = 1;
    }
    cin >> ma;
    for (i = 0; i < ma; i++) {
      cin >> p;
      g[p] = 1;
    }
    numn -= na;
    numm -= ma;
    for (i = 0; i <= 10000; i++) {
      if (b[i % n] == 1 || g[i % m] == 1) {
        if (b[i % n] == 0) {
          b[i % n] = 1;
          numn--;
        }
        if (g[i % m] == 0) {
          g[i % m] = 1;
          numm--;
        }
      }
    }
    if (numn == 0 && numm == 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}
