#include <bits/stdc++.h>
using namespace std;
int mod(int a) {
  if (a < 0) return -a;
  return a;
}
int main() {
  int n, m, i;
  int b, g;
  cin >> n >> m;
  cin >> b;
  int hb[n];
  int hg[m];
  for (i = 0; i < n; i++) hb[i] = 0;
  for (i = 0; i < m; i++) hg[i] = 0;
  for (i = 0; i < b; i++) {
    int x;
    cin >> x;
    hb[x] = 1;
  }
  cin >> g;
  for (i = 0; i < g; i++) {
    int x;
    cin >> x;
    hg[x] = 1;
  }
  for (i = 0; i < (n + 1) * (m + 1); i++) {
    if (hb[i % n] || hg[i % m]) {
      hb[i % n] = hg[i % m] = 1;
    }
  }
  bool flag = false;
  for (i = 0; i < n; i++) {
    if (hb[i] == 0) {
      flag = true;
    }
  }
  for (i = 0; i < m; i++) {
    if (hg[i] == 0) {
      flag = true;
    }
  }
  if (flag)
    cout << "No";
  else
    cout << "Yes";
}
