#include <bits/stdc++.h>
using namespace std;
string tostr(int n) {
  stringstream rr;
  rr << n;
  return rr.str();
}
long long power(long long a, long long b) {
  return b == 0 ?: a * power(a, b - 1);
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  while (cin >> n >> m) {
    int a, b, happyboys[105] = {0}, happygirls[105] = {0};
    cin >> a;
    int arr[a + 5];
    for (int i = 1; i <= a; i++) cin >> arr[i], happyboys[arr[i]] = 1;
    ;
    cin >> b;
    int brr[b + 5];
    for (int i = 1; i <= b; i++) cin >> brr[i], happygirls[brr[i]] = 1;
    int x, y;
    for (int i = 0; i <= 10000; i++) {
      x = i % n;
      y = i % m;
      if (happyboys[x] == 1 || happygirls[y] == 1) {
        happyboys[x] = 1;
        happygirls[y] = 1;
      }
    }
    int flag = 0;
    for (int i = 0; i < n; i++) {
      if (happyboys[i] == 0) {
        flag = 1;
        break;
      }
    }
    for (int i = 0; i < m; i++) {
      if (happygirls[i] == 0) {
        flag = 1;
        break;
      }
    }
    if (flag)
      cout << "No" << endl;
    else
      cout << "Yes" << endl;
  }
  return 0;
}
