#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, b, g, c;
  cin >> n >> m;
  vector<bool> x(n), y(m);
  cin >> b;
  for (int i = 0; i < b; i++) {
    cin >> c;
    x[c] = true;
  }
  cin >> g;
  for (int i = 0; i < g; i++) {
    cin >> c;
    y[c] = true;
  }
  for (int i = 0; i <= 1000000; i++)
    if (x[i % n] || y[i % m]) {
      x[i % n] = true;
      y[i % m] = true;
    }
  bool f = true;
  for (int i = 0; i < n; i++)
    if (!x[i]) f = false;
  for (int i = 0; i < m; i++)
    if (!y[i]) f = false;
  if (f)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}
