#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(m);
  int an;
  cin >> an;
  for (int i = 0; i < an; ++i) {
    int t;
    cin >> t;
    a[t] = 1;
  }
  int bn;
  cin >> bn;
  for (int i = 0; i < bn; ++i) {
    int t;
    cin >> t;
    b[t] = 1;
  }
  int lim = n * m;
  while (1) {
    bool ch = false;
    for (int i = 0; i < lim; ++i) {
      if (a[i % n] != b[i % m]) {
        ch = true;
        a[i % n] = b[i % m] = 1;
      }
    }
    if (!ch) break;
  }
  bool ans = true;
  for (int i = 0; i < n; ++i) ans &= a[i];
  for (int i = 0; i < m; ++i) ans &= b[i];
  cout << (ans ? "Yes" : "No");
  return 0;
}
