#include <bits/stdc++.h>
using namespace std;
long long int a[102], b[102];
int main() {
  long long int n, m;
  cin >> n >> m;
  long long int x;
  cin >> x;
  while (x--) {
    long long int y;
    cin >> y;
    a[y]++;
  }
  cin >> x;
  while (x--) {
    long long int y;
    cin >> y;
    b[y]++;
  }
  for (long long int i = 0; i < 100005; i++) {
    long long int ma = max(a[i % n], b[i % m]);
    a[i % n] = ma;
    b[i % m] = ma;
  }
  long long int tr = 1;
  for (long long int i = 0; i < n; i++) {
    if (a[i] == 0) {
      tr = 0;
    }
  }
  for (long long int j = 0; j < m; j++) {
    if (b[j] == 0) {
      tr = 0;
    }
  }
  if (tr) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
  return 0;
}
