#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000;
int a[maxn], b[maxn];
bool cpa[maxn], cpb[maxn];
int main() {
  int m, n, x, nn, mm;
  cin >> n >> m;
  cin >> nn;
  for (int i = 0; i < nn; i++) {
    cin >> x;
    a[x] = 1;
  }
  cin >> mm;
  for (int i = 0; i < mm; i++) {
    cin >> x;
    b[x] = 1;
  }
  for (int i = 0; i < 10000; i++) {
    if (a[i % n] == 1 || b[i % m] == 1) {
      a[i % n] = 1;
      b[i % m] = 1;
    }
  }
  for (int i = 0; i < n; i++)
    if (a[i] == 0) {
      cout << "No";
      return 0;
    }
  for (int i = 0; i < m; i++)
    if (b[i] == 0) {
      cout << "No";
      return 0;
    }
  cout << "Yes";
  return 0;
}
