#include <bits/stdc++.h>
using namespace std;
int gcf(int A, int B) {
  if (A < B)
    return gcf(B, A);
  else if (B == 0)
    return A;
  else
    return gcf(B, A % B);
}
int main() {
  int n, m;
  cin >> m >> n;
  bool A[m], B[n];
  memset(A, 0, sizeof(A));
  memset(B, 0, sizeof(B));
  int x, y;
  cin >> x;
  for (int i = 0; i < x; i++) {
    int temp;
    cin >> temp;
    A[temp] = 1;
  }
  cin >> y;
  for (int i = 0; i < y; i++) {
    int temp;
    cin >> temp;
    B[temp] = 1;
  }
  for (int i = 0; i < 5000000; i++) {
    if (A[i % m] || B[i % n]) A[i % m] = B[i % n] = 1;
  }
  for (int i = 0; i < m; i++) {
    if (!A[i]) {
      cout << "No";
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (!B[i]) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}
