#include <bits/stdc++.h>
using namespace std;
void online_judge() {}
int small = INT_MIN;
int large = INT_MAX;
void solve() {
  int n, m;
  cin >> n >> m;
  int b, g;
  vector<bool> x(n, false);
  vector<bool> y(m, false);
  cin >> b;
  for (int i = 0; i < b; i++) {
    int z;
    cin >> z;
    x[z] = true;
  }
  cin >> g;
  for (int i = 0; i < g; i++) {
    int z;
    cin >> z;
    y[z] = true;
  }
  int cnt = b + g;
  int i = 0, j = 0;
  bool flag = false;
  long long int k = 1e5;
  while (k--) {
    if (cnt == n + m) {
      flag = true;
      break;
    }
    if (x[i] && !y[j]) {
      y[j] = true;
      cnt++;
    } else if (!x[i] && y[j]) {
      x[i] = true;
      cnt++;
    }
    i = (i + 1) % n;
    j = (j + 1) % m;
  }
  if (flag)
    cout << "Yes";
  else
    cout << "No";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  online_judge();
  long long int t = 1;
  while (t--) solve();
  return 0;
}
