#include <bits/stdc++.h>
using namespace std;
int xx[4] = {0, 0, 1, -1};
int yy[4] = {1, -1, 0, 0};
int n, m, b, s;
int x[int(1e5)], y[int(1e5)];
int main() {
  scanf("%d%d", &n, &m);
  scanf("%d", &b);
  for (int i = (1), _b = (b); i <= _b; i++) {
    scanf("%d", &s);
    x[s] = true;
  }
  scanf("%d", &b);
  for (int i = (1), _b = (b); i <= _b; i++) {
    scanf("%d", &s);
    y[s] = true;
  }
  for (int i = (0), _b = (2 * n * m); i <= _b; i++) {
    int u = i % n;
    int v = i % m;
    if (x[u] || y[v]) {
      x[u] = true;
      y[v] = true;
    }
  }
  for (int i = (0), _b = (n - 1); i <= _b; i++)
    if (!x[i]) {
      cout << "No" << endl;
      return 0;
    }
  for (int i = (0), _b = (m - 1); i <= _b; i++)
    if (!y[i]) {
      cout << "No" << endl;
      return 0;
    }
  cout << "Yes" << endl;
}
