#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, nb, ng;
  cin >> n >> m >> nb;
  vector<int> v(n);
  vector<int> v2(m);
  for (int i = 0; i < nb; i++) {
    int ind;
    cin >> ind;
    v[ind] = 1;
  }
  cin >> ng;
  for (int i = 0; i < ng; i++) {
    int ind;
    cin >> ind;
    v2[ind] = 1;
  }
  v.clear();
  v2.clear();
  long long r = (n * m) * 2;
  for (int i = 0; i < r; i++) {
    if (v[i % n] == 1 || v2[i % m] == 1) v[i % n] = v2[i % m] = 1;
  }
  for (int i = 0; i < n; i++)
    if (v[i] != 1) {
      cout << "No";
      return 0;
    }
  for (int i = 0; i < m; i++)
    if (v2[i] != 1) {
      cout << "No";
      return 0;
    }
  cout << "Yes";
  return 0;
}
