#include <bits/stdc++.h>
using namespace std;
bool boy[110], girl[110], test;
int main() {
  int n, m;
  cin >> n >> m;
  int x, y, z, a, b;
  cin >> x;
  for (int i = 0; i < x; i++) {
    cin >> z;
    boy[z] = 1;
  }
  cin >> y;
  for (int i = 0; i < y; i++) {
    cin >> z;
    girl[z] = 1;
  }
  a = n - x;
  b = m - y;
  test = 0;
  int l = max(n, m) - 1;
  int p = 100, q = 100;
  int cnt = -1;
  for (int i = 0; i < 100000; i++) {
    cnt++;
    p = cnt % n;
    q = cnt % m;
    if (boy[p] == 1 && girl[q] == 0) {
      girl[q] = 1;
      test = 1;
      b--;
    } else if (boy[p] == 0 && girl[q] == 1) {
      boy[p] = 1;
      test = 1;
      a--;
    }
  }
  if (a || b)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}
