#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, b[100] = {0}, g[100] = {0}, t, k, c = 0;
  cin >> n >> m;
  cin >> t;
  while (t--) {
    cin >> k;
    b[k] += 1;
    c += 1;
  }
  cin >> k;
  while (k--) {
    cin >> t;
    g[t] += 1;
    c += 1;
  }
  for (int i = 0; i < 100 * max(n, m); i++) {
    if (b[i % n] + g[i % m] == 1) {
      b[i % n] = g[i % m] = 1;
      c += 1;
    }
  }
  if (c == n + m)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}
