#include <bits/stdc++.h>
using namespace std;
long long int max(long long int a, long long int b) {
  if (a > b) return a;
  return b;
}
long long int min(long long int a, long long int b) {
  if (a < b) return a;
  return b;
}
string sing(char x) {
  string s(1, x);
  return s;
}
bool cmpDec(long long int a, long long int b) {
  if (a >= b) return true;
  return false;
}
void print1D(long long int a[], long long int n) {
  for (long long int i = 0; i < n; i++) cout << a[i] << " ";
  cout << "\n";
}
void print2D(long long int **dp, long long int n, long long int m) {
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) cout << dp[i][j] << " ";
    cout << "\n";
  }
}
long long int fastmod(long long int base, long long int exp, long long int m) {
  long long int res = 1;
  while (exp) {
    if (exp & 1ll) res = (res * base) % m;
    base = (base * base) % m;
    exp /= 2;
  }
  return res;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int logBase(long long int m, long long int b) {
  long long int count = 0;
  while (m > 1) {
    ++count;
    m = m / b;
  }
  return count;
}
long long int spf[100000 + 1];
void sieve() {
  spf[1] = 1;
  for (long long int i = 2; i < 100000 + 1; i++) spf[i] = i;
  for (long long int i = 4; i < 100000 + 1; i += 2) spf[i] = 2;
  for (long long int i = 3; i * i < 100000 + 1; i++) {
    if (spf[i] == i) {
      for (long long int j = i * i; j < 100000 + 1; j += i)
        if (spf[j] == j) spf[j] = i;
    }
  }
}
vector<int> getFactorization(int x) {
  vector<int> ret;
  while (x != 1) {
    ret.push_back(spf[x]);
    x = x / spf[x];
  }
  return ret;
}
long long int sumofFactors(long long int n) {
  long long int res = 1;
  for (long long int i = 2; i <= sqrt(n); i++) {
    long long int curr_sum = 1;
    long long int curr_term = 1;
    while (n % i == 0) {
      n = n / i;
      curr_term *= i;
      curr_sum += curr_term;
    }
    res *= curr_sum;
  }
  if (n >= 2) res *= (1 + n);
  return res;
}
void SUM(long long int *a, long long int n) {
  long long int sum = 0;
  for (long long int i = 0; i < n; i++) sum += a[i];
  cout << sum << "\n";
}
void addEdge(vector<long long int> adj[], long long int u, long long int v) {
  adj[u].push_back(v);
  adj[v].push_back(u);
}
void printGraph(vector<long long int> adj[], long long int V) {
  for (long long int v = 1; v < V; ++v) {
    cout << "\n Adjacency list of vertex " << v << "\n head (" << v << ")";
    for (long long int x = 0; x < adj[v].size(); x++)
      cout << " -> " << adj[v][x];
    printf("\n");
  }
}
bool cycle(vector<long long int> adj[], long long int vis[], long long int n,
           long long int parent) {
  vis[n] = 1;
  if (adj[n].empty()) return false;
  bool value = false;
  for (long long int i = 0; i < adj[n].size(); i++) {
    if (adj[n][i] != parent) {
      if (vis[adj[n][i]] == 1)
        return true;
      else
        value |= cycle(adj, vis, adj[n][i], n);
    }
  }
  return value;
}
typedef struct num {
  long long int index;
  long long int value;
} num;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  long long int g = gcd(n, m);
  long long int *a;
  a = new long long int[g];
  for (long long int i = 0; i < g; i++) a[i] = 0;
  long long int b;
  int x;
  cin >> b;
  for (long long int i = 0; i < b; i++) {
    cin >> x;
    a[x % g] |= 1;
  }
  cin >> b;
  for (long long int i = 0; i < b; i++) {
    cin >> x;
    a[x % g] |= 1;
  }
  for (long long int i = 0; i < g; i++) {
    if (a[i] == 0) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
}
