#include <bits/stdc++.h>
using namespace std;
int ha[100], hb[100];
int main() {
  int n, m;
  cin >> n >> m;
  int nha, nhb;
  cin >> nha;
  for (int i = 0; i < nha; i++) {
    int k;
    cin >> k;
    ha[k]++;
  }
  cin >> nhb;
  for (int i = 0; i < nhb; i++) {
    int k;
    cin >> k;
    hb[k]++;
  }
  int nh = nha + nhb;
  for (int i = 0; i < 2 * n * m; i++) {
    int a = i % n;
    int b = i % m;
    if (ha[a] + hb[b] == 1) {
      ha[a] = hb[b] = 1;
      ++nh;
    }
  }
  cout << ((nh == (n + m)) ? "Yes" : "No") << endl;
}
