#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int boy[110], girl[110];
int h[110];
int main() {
  int m, n, h_n, h_m, flag = 1;
  ;
  cin >> n >> m;
  int g = gcd(n, m);
  memset(h, 0, sizeof(h));
  cin >> h_n;
  for (int i = 0; i < h_n; i++) {
    cin >> boy[i];
    h[boy[i] % g] = 1;
  }
  cin >> h_m;
  for (int i = 0; i < h_m; i++) {
    cin >> girl[i];
    h[girl[i] % g] = 1;
  }
  for (int i = 0; i < g; i++) {
    if (h[i] == 0) {
      flag = 0;
      break;
    }
  }
  if (flag)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}
