#include <bits/stdc++.h>
using namespace std;
int main() {
  int bys, grs;
  map<int, bool> b, g;
  cin >> bys >> grs;
  int bh;
  cin >> bh;
  for (int i = 0; i < bh; i++) {
    int temp;
    cin >> temp;
    b[temp] = true;
  }
  int gh;
  cin >> gh;
  for (int i = 0; i < gh; i++) {
    int temp;
    cin >> temp;
    g[temp] = true;
  }
  if (!(bh + gh)) {
    cout << "No";
  } else {
    bool st = false;
    int t = max(bys, grs) * (bys + grs);
    int n = bh + gh;
    for (int i = 0; i < t; i++) {
      if (n == bys + grs) {
        st = true;
        break;
      }
      if ((b[i % bys] == true && g[i % grs] == false) ||
          (b[i % bys] == false && g[i % grs] == true)) {
        b[i % bys] = true;
        g[i % grs] = true;
        n++;
      }
    }
    if (st)
      cout << "Yes";
    else
      cout << "No";
  }
  return 0;
}
