#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int b;
  cin >> b;
  vector<int> boys(n, 0);
  for (int i = 0; i < b; ++i) {
    int tmp;
    cin >> tmp;
    boys[tmp] = 1;
  }
  int g;
  cin >> g;
  vector<int> girls(m, 0);
  for (int i = 0; i < g; ++i) {
    int tmp;
    cin >> tmp;
    girls[tmp] = 1;
  }
  set<int> cb;
  set<int> cg;
  long long ch = (n + m) * n * m;
  for (int i = 0; i < ch; i++) {
    if (boys[i % n] || girls[i % m]) {
      cb.insert(i % n);
      cg.insert(i % m);
      boys[i % n] = 1;
      girls[i % m] = 1;
    }
  }
  if (cb.size() == n && cg.size() == m) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}
