#include <bits/stdc++.h>
using namespace std;
template <typename _type>
void outArray(_type a[], long long n) {
  for (long long i = 1; i <= n; i++) cout << a[i] << " ";
  cout << endl;
}
template <typename _type>
void outMatrix(_type a[][10005], long long n, long long m) {
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) cout << a[i][j] << " ";
    cout << endl;
  }
}
long long n, m, b, g;
long long x[1005] = {0};
long long y[1005] = {0};
int main() {
  long long i, j, k, le, ri;
  cin >> n >> m;
  cin >> b;
  for (i = 1; i <= b; i++) {
    cin >> j;
    x[j] = 1;
  }
  cin >> g;
  for (i = 1; i <= g; i++) {
    cin >> k;
    y[k] = 1;
  }
  for (i = 0; i <= 100 * n * m; i++) {
    j = i % n;
    k = i % m;
    if (x[j] == 1 || y[k] == 1) x[j] = y[k] = 1;
  }
  bool f = true;
  for (i = 0; i <= n - 1; i++)
    if (x[i] == 0) f = false;
  for (i = 0; i <= m - 1; i++)
    if (y[i] == 0) f = false;
  if (f)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}
