#include <bits/stdc++.h>
template <typename T>
T pow(T a, T b, long long m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans % m;
}
using namespace std;
bool B[100], G[100];
int main() {
  int n, m;
  cin >> n >> m;
  int b;
  cin >> b;
  for (int(i) = (0); (i) < (b); (i)++) {
    int first;
    cin >> first;
    B[first] = 1;
  }
  int g;
  cin >> g;
  for (int(i) = (0); (i) < (g); (i)++) {
    int first;
    cin >> first;
    G[first] = 1;
  }
  for (int(i) = (0); (i) < (10000000); (i)++)
    B[i % n] = G[i % m] = B[i % n] | G[i % m];
  bool boys = 1, girls = 1;
  for (int(i) = (0); (i) < (n); (i)++) boys &= B[i];
  for (int(i) = (0); (i) < (m); (i)++) girls &= G[i];
  if (boys && girls)
    cout << "Yes" << '\n';
  else
    cout << "No" << '\n';
  return 0;
}
