#include <bits/stdc++.h>
using namespace std;
bool chck(bool hb[410], bool hg[410], int b, int g) {
  for (int i = 0; i < b; i++)
    if (!hb[i]) return false;
  for (int i = 0; i < g; i++)
    if (!hg[i]) return false;
  return true;
}
int main() {
  int n, m, h1, h2, a[410], b[410];
  bool hb[410] = {0}, hg[410] = {0}, flag = 0;
  cin >> n >> m >> h1;
  for (int i = 0; i < h1; i++) {
    cin >> a[i];
    hb[a[i]] = 1;
  }
  cin >> h2;
  for (int i = 0; i < h2; i++) {
    cin >> b[i];
    hg[b[i]] = 1;
  }
  if (h1 == 0 && h2 == 0) {
    cout << "No\n";
    return 0;
  }
  for (int i = 0; i < 10010; i++) {
    if (hb[(i % n + n) % n] || hg[(i % m + m) % m])
      hb[(i % n + n) % n] = hg[(i % m + m) % m] = 1;
    if (chck(hb, hg, n, m)) {
      flag = 1;
      break;
    }
  }
  if (flag)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}
