#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void solve() {
  long long n, m;
  cin >> n >> m;
  long long b[n], g[m], k, l;
  for (long long i = 0; i < n; i++) b[i] = 0;
  for (long long i = 0; i < m; i++) g[i] = 0;
  cin >> k;
  for (long long i = 0; i < k; i++) {
    cin >> l;
    b[l] = 1;
  }
  cin >> k;
  for (long long i = 0; i < k; i++) {
    cin >> l;
    g[l] = 1;
  }
  long long q = 2 * (n * m);
  long long ind1 = 0, ind2 = 0;
  while (q--) {
    if (b[ind1] == 1 or g[ind2] == 1) {
      b[ind1] = 1;
      g[ind2] = 1;
    }
    ind1 = (ind1 + 1) % n;
    ind2 = (ind2 + 1) % m;
  }
  bool f = false;
  for (long long i = 0; i < n; i++) {
    if (b[i] == 0) {
      f = true;
      break;
    }
  }
  for (long long i = 0; i < m; i++) {
    if (g[i] == 0) {
      f = true;
      break;
    }
  }
  if (f)
    cout << "No\n";
  else
    cout << "Yes\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
}
