#include <bits/stdc++.h>
using namespace std;
const int mod = 5 * 100010;
int hap1[110], hap2[110];
int pairs[110][110];
char a[20];
int dig[12];
int gcd(int a, int b) { return (!b ? a : gcd(b, a % b)); }
int main() {
  int n, m;
  int dif = 0;
  cin >> n >> m;
  int b, g;
  cin >> b;
  for (int i = 0; i < b; ++i) {
    int k;
    cin >> k;
    hap1[k] = 1;
  }
  cin >> g;
  for (int i = 0; i < g; ++i) {
    int k;
    cin >> k;
    hap2[k] = 1;
  }
  for (int i = 0; i <= 1000010; ++i) {
    int cnt = i % n;
    int dop = i % m;
    if (hap1[cnt] || hap2[dop]) {
      if (hap2[dop])
        hap1[cnt] = 1;
      else
        hap2[dop] = 1;
    }
  }
  int flag = 1;
  for (int i = 0; i < n; ++i) {
    if (!hap1[i]) {
      flag = 0;
    }
  }
  if (!flag) {
    cout << "No" << endl;
    return 0;
  }
  flag = 1;
  for (int i = 0; i < m; ++i) {
    if (!hap2[i]) {
      flag = 0;
    }
  }
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
