#include <bits/stdc++.h>
using namespace std;
void faster() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
const long long INF = 1e18;
const long long MAXN = 2e5 + 123;
const long double EPS = 1e-12;
const long long MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};
long long T, n, m, k, cnt, uf[MAXN], um[MAXN];
void solve() {
  cin >> n >> m;
  cin >> k;
  for (int i = 0, x; i < k; ++i) {
    cin >> x;
    um[x] = 1;
    cnt++;
  }
  cin >> k;
  for (int i = 0, x; i < k; ++i) {
    cin >> x;
    uf[x] = 1;
    cnt++;
  }
  for (int i = 0; i < n * m * n * m; ++i) {
    if ((um[i % n] | uf[i % m])) {
      cnt += (um[i % n] == 0) + (uf[i % m] == 0);
      um[i % n] = uf[i % m] = 1;
    }
  }
  if (cnt == n + m)
    cout << "Yes\n";
  else
    cout << "No\n";
}
int main() {
  faster();
  T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
