#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, b, g;
  cin >> n >> m;
  int bo[n];
  int gi[m];
  set<int> b1;
  set<int> g1;
  memset(bo, 0, sizeof(bo));
  memset(gi, 0, sizeof(gi));
  cin >> b;
  for (i = 0; i < b; i++) {
    cin >> j;
    bo[j] = 1;
    b1.insert(j);
  }
  cin >> g;
  for (i = 0; i < g; i++) {
    cin >> j;
    gi[j] = 1;
    g1.insert(j);
  }
  set<int> b2;
  set<int> g2;
  i = 0;
  j = 0;
  while (j <= n * m) {
    if (b1 == b2 && g1 == g2) {
      j++;
    } else {
      j = 0;
    }
    b2 = b1;
    g2 = g1;
    if (bo[i % n] == 1 || gi[i % m] == 1) {
      bo[i % n] = 1;
      gi[i % m] = 1;
      b1.insert(i % n);
      g1.insert(i % m);
    }
    i++;
  }
  if (g1.size() == m && b1.size() == n) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}
