#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int v1[101] = {0};
  int v2[101] = {0};
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    v1[x] = 1;
  }
  cin >> N;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    v2[x] = 1;
  }
  for (int i = 0; i < n * m * 2; i++) {
    if (v1[i % n] == 1 || v2[i % m] == 1) {
      v1[i % n] = 1;
      v2[i % m] = 1;
    }
  }
  bool f1 = true, f2 = true;
  for (int i = 0; i < n; i++) {
    if (v1[i] == 0) {
      f1 = false;
      break;
    }
  }
  for (int i = 0; i < m; i++) {
    if (v2[i] == 0) {
      f2 = false;
      break;
    }
  }
  if (f1 && f2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
