#include <bits/stdc++.h>
using namespace std;
int n, m, i, nb, ng, temp, sol;
bool b[1001], g[1001];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  cin >> nb;
  sol += nb;
  for (i = 0; i < nb; i++) {
    cin >> temp;
    b[temp] = 1;
  }
  cin >> ng;
  sol += ng;
  for (i = 0; i < ng; i++) {
    cin >> temp;
    g[temp] = 1;
  }
  for (i = 0; i < 10000000; i++) {
    if (b[i % n] || g[i % m]) {
      if (!b[i % n]) {
        b[i % n] = 1;
        sol++;
      }
      if (!g[i % m]) {
        g[i % m] = 1;
        sol++;
      }
    }
    if (sol == n + m) break;
  }
  if (sol == n + m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
