#include <bits/stdc++.h>
using namespace std;
long long MAX = 1e17;
long long MOD = 1e9 + 7;
vector<long long> adj[10];
long long arr[101];
long long brr[101];
void initialize() {
  for (long long i = 0; i < 101; i++) {
    arr[i] = 0;
    brr[i] = 0;
  }
}
long long root(long long i) {
  while (arr[i] != i) {
    arr[i] = arr[arr[i]];
    i = arr[i];
  }
  return i;
}
void unionn(long long i, long long j) {
  long long a = root(i);
  long long b = root(j);
  arr[a] = arr[b];
}
bool iscommon(vector<long long> a, vector<long long> b) {
  long long n = a.size(), m = b.size();
  unordered_map<long long, long long> um;
  for (long long i = 0; i < n; i++) um[a[i]] = 1;
  for (long long i = 0; i < m; i++)
    if (um.find(b[i]) != um.end()) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  vector<long long> v[n];
  initialize();
  long long len, x;
  cin >> len;
  for (long long j = 0; j < len; j++) {
    cin >> x;
    arr[x] = 1;
  }
  cin >> len;
  for (long long j = 0; j < len; j++) {
    cin >> x;
    brr[x] = 1;
  }
  long long p = 100000;
  for (long long i = 0; i < p; i++) {
    long long a = i % n, b = i % m;
    if (arr[a] == 0 && brr[b] == 1) {
      arr[a] = 1;
    } else if (arr[a] == 1 && brr[b] == 0) {
      brr[b] = 1;
    }
  }
  bool ok = true;
  for (long long i = 0; i < n; i++)
    if (arr[i] == 0) ok = false;
  for (long long i = 0; i < m; i++)
    if (brr[i] == 0) ok = false;
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
