#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("-Ofast", "-funroll-all-loops", "-ffast-math")
using namespace std;
using LL = long long;
constexpr int mod = 1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long ex_gcd(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  long long ret = ex_gcd(b, a % b, y, x);
  y -= a / b * x;
  return ret;
}
LL bin(LL x, LL n, LL MOD) {
  LL ret = MOD != 1;
  for (x %= MOD; n; n >>= 1, x = x * x % MOD)
    if (n & 1) ret = ret * x % MOD;
  return ret;
}
int norm(int x) { return x >= mod ? (x - mod) : x; }
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
inline long long get_inv(long long a) {
  long long x, y;
  ex_gcd(a, mod, x, y);
  return norm(x + mod);
}
template <class T>
inline void umin(T &x, T y) {
  x = x > y ? y : x;
}
template <class T>
inline void umax(T &x, T y) {
  x = x < y ? y : x;
}
template <class T>
inline void dec(T &x, T y) {
  x -= y;
  if (x < 0) x += mod;
}
template <class T>
inline void add(T &x, T y) {
  x += y;
  if (x >= mod) x -= mod;
}
const double PI = acos(-1.0);
constexpr int INF = 0x3f3f3f3f;
constexpr long long linf = 0x3f3f3f3f3f3f3f3f;
constexpr unsigned long long base = 2333, P_1 = 19260817, P_2 = 999998639;
constexpr int maxn = 1e6 + 10;
int n, m, a[maxn], b[maxn];
int main() {
  std::ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr),
      cout << fixed << setprecision(10);
  cin >> n >> m;
  int x;
  cin >> x;
  for (int i = 1; i <= x; i++) {
    int t;
    cin >> t;
    a[t] = 1;
  }
  cin >> x;
  for (int i = 1; i <= x; i++) {
    int t;
    cin >> t;
    b[t] = 1;
  }
  for (int i = 0; i < 100 * 100 + 10; i++) {
    if (a[i % n]) {
      b[i % m] = 1;
    }
    if (b[i % m]) {
      a[i % n] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (!a[i]) {
      cout << "No" << '\12';
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    if (!b[i]) {
      cout << "No" << '\12';
      return 0;
    }
  }
  cout << "Yes" << '\12';
  return 0;
}
