#include <bits/stdc++.h>
using namespace std;
struct disjoint_set {
  int n, m;
  vector<int> par, deg;
  vector<int> happy;
  disjoint_set() {}
  disjoint_set(int n_, int m_) {
    n = n_;
    m = m_;
    int sz = n + m;
    par.resize(sz);
    deg.resize(sz);
    happy.resize(sz);
    for (int i = 0; i < sz; i++) par[i] = i, deg[i] = 0, happy[i] = 0;
  }
  int find_par(int cur) {
    if (cur == par[cur]) return cur;
    return par[cur] = find_par(par[cur]);
  }
  bool join(int b, int g, bool one_is_happy) {
    int x = b;
    int y = g + n;
    x = find_par(x);
    y = find_par(y);
    happy[x] |= one_is_happy | happy[y];
    happy[y] |= one_is_happy | happy[x];
    if (x == y) return 0;
    if (deg[x] < deg[y]) swap(x, y);
    if (deg[x] == deg[y]) deg[x]++;
    par[y] = x;
    return 1;
  }
  bool is_happy(int cur) { return happy[find_par(cur)]; }
};
bool b[105], g[105];
int main() {
  int n, m;
  cin >> n >> m;
  int cnt;
  cin >> cnt;
  for (int i = 0; i < cnt; i++) {
    int x;
    cin >> x;
    b[x] = 1;
  }
  cin >> cnt;
  for (int i = 0; i < cnt; i++) {
    int x;
    cin >> x;
    g[x] = 1;
  }
  disjoint_set dsu(n, m);
  for (int i = 0; i < n * m; i++) {
    dsu.join(i % n, i % m, b[i % n] | g[i % m]);
  }
  bool yes = 1;
  for (int i = 0; i < n + m; i++)
    if (dsu.is_happy(i) == 0) yes = 0;
  cout << (yes ? "Yes\n" : "No\n");
  return 0;
}
