#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5 + 5;
const int M = 1e6;
const long long INF = (long long)(1e18);
const int inf = 1e9;
const long long MOD = 1000000007LL;
int n, m;
int b, g;
bool happyBoy[105], happyGirl[105];
set<int> unhappyBoy, unhappyGirl;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  cin >> b;
  for (int i = 0; i < n; i++) {
    unhappyBoy.insert(i);
  }
  for (int i = 0; i < m; i++) {
    unhappyGirl.insert(i);
  }
  for (int i = 0; i < b; i++) {
    int x;
    cin >> x;
    happyBoy[x] = true;
    unhappyBoy.erase(x);
  }
  cin >> g;
  for (int i = 0; i < g; i++) {
    int x;
    cin >> x;
    happyGirl[x] = true;
    unhappyGirl.erase(x);
  }
  int boy = 0;
  int girl = 0;
  for (int rep = 0; rep < MAX_N; rep++) {
    if (unhappyBoy.empty() && unhappyGirl.empty()) {
      break;
    }
    if (happyBoy[boy] && !happyGirl[girl]) {
      happyGirl[girl] = true;
      unhappyGirl.erase(girl);
    }
    if (!happyBoy[boy] && happyGirl[girl]) {
      happyBoy[boy] = true;
      unhappyBoy.erase(boy);
    }
    boy = (boy + 1) % n;
    girl = (girl + 1) % m;
  }
  if (unhappyBoy.empty() && unhappyGirl.empty()) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}
