#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> V(n, 0), W(m, 0);
  while (k--) {
    int aux;
    cin >> aux;
    V[aux] = 1;
  }
  cin >> k;
  while (k--) {
    int aux;
    cin >> aux;
    W[aux] = 1;
  }
  for (int i = 0; i < n; ++i) {
    int ind = 0;
    while (ind < m) {
      int j = i + ind * n;
      if (W[j % m]) {
        V[i] = 1;
      }
      ind++;
    }
    ind = 0;
    if (V[i] == 1) {
      while (ind < m) {
        int j = i + ind * n;
        W[j % m] = 1;
        ind++;
      }
    }
  }
  for (int i = 0; i < m; ++i) {
    int ind = 0;
    while (ind < n) {
      int j = i + ind * m;
      if (V[j % n]) {
        W[i] = 1;
      }
      ind++;
    }
    ind = 0;
    if (W[i] == 1) {
      while (ind < n) {
        int j = i + ind * m;
        V[j % n] = 1;
        ind++;
      }
    }
  }
  bool mark = true;
  for (int i = 0; i < n; ++i) {
    if (!V[i]) {
      mark = false;
    }
  }
  for (int i = 0; i < m; ++i) {
    if (!W[i]) {
      mark = false;
    }
  }
  if (mark) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}
