#include <bits/stdc++.h>
using namespace std;
map<int, int> mp1, mp2;
int main() {
  int i, j, k, n, m, b, g, val;
  cin >> n >> m;
  cin >> b;
  while (b--) {
    cin >> val;
    mp1[val] = 1;
  }
  val = 0;
  cin >> g;
  while (g--) {
    cin >> val;
    mp2[val] = 1;
  }
  for (i = 0; i < 10000; i++) {
    if (mp1[i % n] == 1 and mp2[i % m] == 1)
      continue;
    else if (mp1[i % n] == 0 and mp2[i % m] == 0)
      continue;
    else if (mp1[i % n] == 1 and mp2[i % m] == 0) {
      mp2[i % m] = 1;
    } else if (mp1[i % n] == 0 and mp2[i % m] == 1) {
      mp1[i % n] = 1;
    }
  }
  int c1 = 0;
  for (i = 0; i < n; i++) {
    if (mp1[i] == 0) {
      c1++;
    }
  }
  int c2 = 0;
  for (i = 0; i < m; i++) {
    if (mp2[i] == 0) {
      c2++;
    }
  }
  if (c1 == 0 and c2 == 0)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}
