#include <bits/stdc++.h>
using namespace std;
const int M = 1004;
int n, m, x, y, a, b, u, v, o;
bool hp_m[M], hp_w[M], ok, ch = true;
void dinner(int h, int k) {
  int initial1 = hp_m[h], initial2 = hp_w[k];
  if (hp_m[h] == 1 || hp_w[k] == 1) hp_m[h] = 1, hp_w[k] = 1;
  if (initial1 != hp_m[h]) ch = true;
  if (initial2 != hp_w[k]) ch = true;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i <= n - 1; i++) hp_m[i] = 0;
  for (int i = 0; i <= m - 1; i++) hp_w[i] = 0;
  cin >> x;
  for (int i = 1; i <= x; i++) cin >> a, hp_m[a] = 1;
  cin >> y;
  for (int i = 1; i <= y; i++) cin >> b, hp_w[b] = 1;
  while (ch == true) {
    dinner(0, 0);
    u = 1 % n, v = 1 % m, o = 1, ch = false;
    while (u != 0 || v != 0) {
      dinner(u, v);
      o++;
      u = o % n;
      v = o % m;
    }
  }
  ok = true;
  for (int i = 0; i <= n - 1; i++)
    if (hp_m[i] == 0) ok = false;
  for (int i = 0; i <= m - 1; i++)
    if (hp_w[i] == 0) ok = false;
  if (ok)
    cout << "Yes";
  else
    cout << "No";
}
