#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int gcd(int n, int m) {
  if (n % m == 0)
    return m;
  else
    gcd(m, n % m);
}
int main() {
  int n, m;
  cin >> n >> m;
  int b, g;
  int nb[n + 1], mg[m + 1];
  memset(nb, 0, sizeof(nb));
  memset(mg, 0, sizeof(mg));
  cin >> b;
  int a[b], i;
  for (i = 0; i < b; i++) {
    cin >> a[i];
    nb[a[i]] = 1;
  }
  cin >> g;
  int c[g];
  for (i = 0; i < g; i++) {
    cin >> c[i];
    mg[c[i]] = 1;
  }
  queue<int> q;
  queue<int> ch;
  for (i = 0; i < n; i++) {
    if (nb[i] == 1) {
      q.push(i);
      ch.push(1);
    }
  }
  for (i = 0; i < m; i++) {
    if (mg[i] == 1) {
      q.push(i);
      ch.push(0);
    }
  }
  if (!q.empty()) {
  }
  int l1 = gcd(n, m);
  l1 = (n * m) / l1;
  int visitb[n + 1], visitg[m + 1];
  memset(visitb, 0, sizeof(visitb));
  memset(visitg, 0, sizeof(visitg));
  while (!q.empty()) {
    int k = q.front();
    int l = ch.front();
    q.pop();
    ch.pop();
    if (l == 1 && visitb[k] == 0) {
      visitb[k] = 1;
      while (k <= l1) {
        int v;
        if (k % m == 0) {
          v = k % m;
        } else {
          v = (k % m);
        }
        if (visitg[v] == 0) {
          mg[v] = 1;
          q.push(v);
          ch.push(0);
        }
        k += n;
      }
    } else if (l == 0 && visitg[k] == 0) {
      visitg[k] = 1;
      while (k <= l1) {
        int v;
        if (k % n == 0) {
          v = k % n;
        } else {
          v = k % n;
        }
        if (visitb[v] == 0) {
          nb[v] = 1;
          q.push(v);
          ch.push(1);
        }
        k += m;
      }
    }
  }
  int t = 0;
  for (i = 0; i < n; i++) {
    if (nb[i] == 0) {
      t = 1;
      break;
    }
  }
  if (t == 1) {
    cout << "No";
    return 0;
  }
  for (i = 0; i < m; i++) {
    if (mg[i] == 0) {
      t = 1;
      break;
    }
  }
  if (t == 1) {
    cout << "No";
    return 0;
  }
  cout << "Yes";
  return 0;
}
