#include <bits/stdc++.h>
using namespace std;
int n, m, x, b, q, a[111], w[111];
int main() {
  cin >> n >> m;
  cin >> b;
  for (int i = 0; i < b; i++) {
    cin >> x;
    a[x] = 1;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> x;
    w[x] = 1;
  }
  for (int i = 0; i < 100000; i++)
    if (a[i % n] || w[i % m]) a[i % n] = 1, w[i % m] = 1;
  for (int i = 0; i < n; i++)
    if (!a[i]) {
      cout << "No";
      return 0;
    }
  for (int i = 0; i < m; i++)
    if (!w[i]) {
      cout << "No";
      return 0;
    }
  cout << "Yes";
  return 0;
}
