#include <bits/stdc++.h>
using namespace std;
struct DisjointSet {
  int root, rank;
} S[102];
bool isHappy[2][102], isHappySet[2 * 102];
pair<int, int> E[102 * 102];
vector<int> A[2 * 102];
int GCD(int n1, int n2) {
  int rem;
  while (n2) {
    rem = n1 % n2;
    n1 = n2, n2 = rem;
  }
  return n1;
}
int LCM(int n1, int n2) { return n1 * n2 / GCD(n1, n2); }
void initialize_sets(int n) {
  for (int i = 0; i < n; ++i) S[i].root = i, S[i].rank = 0;
}
int find_set(int u) {
  return S[u].root == u ? u : (S[u].root = find_set(S[u].root));
}
void union_sets(int s1, int s2) {
  if (S[s1].rank < S[s2].rank)
    S[s1].root = s2;
  else if (S[s1].rank > S[s2].rank)
    S[s2].root = s1;
  else
    S[s2].root = s1, S[s1].rank++;
}
bool solve(int n1, int n2) {
  int lcm = LCM(n1, n2), m = 0, s1, s2, i;
  for (i = 0; i < lcm; ++i) E[m++] = pair<int, int>(i % n1, n1 + i % n2);
  initialize_sets(n1 + n2);
  for (i = 0; i < m; ++i) {
    s1 = find_set(E[i].first), s2 = find_set(E[i].second);
    if (s1 != s2) union_sets(s1, s2);
  }
  for (i = 0; i < n1; ++i)
    if (isHappy[0][i]) isHappySet[find_set(i)] = true;
  for (i = 0; i < n2; ++i)
    if (isHappy[1][i]) isHappySet[find_set(n1 + i)] = true;
  for (i = 0; i < n1 && (isHappy[0][i] || isHappySet[find_set(i)]); ++i)
    ;
  if (i < n1) return false;
  for (i = 0; i < n2 && (isHappy[1][i] || isHappySet[find_set(n1 + i)]); ++i)
    ;
  return i == n2;
}
int main() {
  int n1, n2, c, k, i;
  scanf("%d %d", &n1, &n2);
  for (i = 0; i < 2; ++i)
    for (scanf("%d", &c); c; --c) {
      scanf("%d", &k);
      isHappy[i][k] = true;
    }
  puts(solve(n1, n2) ? "Yes" : "No");
  return 0;
}
