#include <bits/stdc++.h>
using namespace std;
int n, m, b, xi, g, yi;
bool bisa = 1;
pair<int, bool> parent[200];
int fp(int x) {
  if (parent[x].first != x) {
    parent[x].first = fp(parent[x].first);
  }
  return parent[x].first;
}
void join(int x, int y) {
  x = fp(x);
  y = fp(y);
  parent[x].second |= parent[y].second;
  parent[y].second |= parent[x].second;
  parent[y].first = x;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    parent[i].first = i;
  }
  for (int i = 0; i < m; i++) {
    parent[i + n].first = i + n;
  }
  cin >> b;
  while (b--) {
    cin >> xi;
    parent[xi].second = 1;
  }
  cin >> g;
  while (g--) {
    cin >> yi;
    parent[yi + n].second = 1;
  }
  b = 0;
  g = 0;
  for (int k = 0; k < n * m; k++) {
    join(b, g + n);
    b++;
    b %= n;
    g++;
    g %= m;
  }
  for (int i = 0; i < n; i++) {
    bisa &= parent[fp(i)].second;
  }
  for (int i = 0; i < m; i++) {
    bisa &= parent[fp(i + n)].second;
  }
  if (bisa) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}
