#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, k, ok, f, b, bf[10010], ff[10010];
vector<int> g[10010];
int main() {
  cin >> n >> m;
  cin >> x;
  for (int i = 1; i <= x; i++) {
    cin >> k;
    bf[k] = 1;
  }
  cin >> y;
  for (int i = 1; i <= y; i++) {
    cin >> k;
    ff[k] = 1;
  }
  do {
    ok = 0;
    for (int i = 0; i <= n * m - 1; i++) {
      b = i % n;
      f = i % m;
      if (bf[b] && !ff[f])
        ff[f] = 1, ok = 1;
      else if (!bf[b] && ff[f])
        bf[b] = 1, ok = 1;
    }
  } while (ok);
  for (int i = 0; i <= n - 1; i++)
    if (!bf[i]) {
      cout << "No";
      return 0;
    }
  for (int i = 0; i <= m - 1; i++)
    if (!ff[i]) {
      cout << "No";
      return 0;
    }
  cout << "Yes";
}
