#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, b, g, cnt = 0, boys[105] = {0}, girls[105] = {0}, i, j, x, inviteb,
                  inviteg;
  cin >> n >> m;
  cin >> b;
  for (i = 0; i < b; i++) {
    cin >> x;
    boys[x] = 1;
  }
  cin >> g;
  for (i = 0; i < g; i++) {
    cin >> x;
    girls[x] = 1;
  }
  cnt = b + g;
  i = 0;
  inviteb = 0;
  inviteg = 0;
  if (boys[inviteb] == 1 && girls[inviteg] == 0) {
    cnt++;
    girls[inviteg] = 1;
  } else if (boys[inviteb] == 0 && girls[inviteg] == 1) {
    cnt++;
    boys[inviteb] = 1;
  }
  i = 1;
  while (cnt <= n + m) {
    inviteb = i % n;
    inviteg = i % m;
    if (inviteb == 0 && inviteg == 0) break;
    if (boys[inviteb] == 1 && girls[inviteg] == 0) {
      cnt++;
      girls[inviteg] = 1;
    } else if (boys[inviteb] == 0 && girls[inviteg] == 1) {
      cnt++;
      boys[inviteb] = 1;
    }
    i++;
  }
  i = 0;
  inviteb = 0;
  inviteg = 0;
  if (boys[inviteb] == 1 && girls[inviteg] == 0) {
    cnt++;
    girls[inviteg] = 1;
  } else if (boys[inviteb] == 0 && girls[inviteg] == 1) {
    cnt++;
    boys[inviteb] = 1;
  }
  i = 1;
  while (cnt <= n + m) {
    inviteb = i % n;
    inviteg = i % m;
    if (inviteb == 0 && inviteg == 0) break;
    if (boys[inviteb] == 1 && girls[inviteg] == 0) {
      cnt++;
      girls[inviteg] = 1;
    } else if (boys[inviteb] == 0 && girls[inviteg] == 1) {
      cnt++;
      boys[inviteb] = 1;
    }
    i++;
  }
  if (cnt == n + m)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}
