#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  long long d;
  cin >> d;
  vector<long long> x, y;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    a[i] = 0;
  }
  for (long long i = 1; i <= d; i++) {
    long long q;
    cin >> q;
    x.push_back(q);
  }
  for (long long i = 0; i < x.size(); i++) {
    a[x[i]] = 1;
  }
  long long g;
  cin >> g;
  for (long long i = 1; i <= g; i++) {
    long long q;
    cin >> q;
    y.push_back(q);
  }
  long long b[m];
  for (long long i = 0; i < m; i++) {
    b[i] = 0;
  }
  for (long long i = 0; i < y.size(); i++) {
    b[y[i]] = 1;
  }
  for (long long i = 0; i <= n * m * (n + m); i++) {
    if (a[i % n] != b[i % m]) {
      a[i % n] = 1;
      b[i % m] = 1;
    }
  }
  bool flag = true;
  for (long long i = 0; i < n; i++) {
    if (a[i] != 1) {
      flag = false;
      break;
    }
  }
  for (long long i = 0; i < m; i++) {
    if (b[i] != 1) {
      flag = false;
      break;
    }
  }
  if (!flag) {
    cout << "No" << '\n';
  } else {
    cout << "Yes" << '\n';
  }
  return 0;
}
