#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int boy[n], girl[m], i;
  int b, g;
  cin >> b;
  for (i = 0; i < n; i++) boy[i] = 0;
  for (i = 0; i < m; i++) girl[i] = 0;
  for (i = 0; i < b; i++) {
    int x;
    cin >> x;
    boy[x] = 1;
  }
  cin >> g;
  for (i = 0; i < g; i++) {
    int x;
    cin >> x;
    girl[x] = 1;
  }
  for (i = 0; i < 10000000; i++) {
    if (boy[i % n] || girl[i % m]) {
      boy[i % n] = 1;
      girl[i % m] = 1;
    }
  }
  for (i = 0; i < n; i++) {
    if (!boy[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  for (i = 0; i < m; i++) {
    if (!girl[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}
