#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m, b, g, tmp, flag = 0;
  int x[109] = {0};
  int y[109] = {0};
  cin >> n >> m;
  cin >> b;
  for (int i = 0; i < b; i++) {
    cin >> tmp;
    x[tmp] = 1;
  }
  cin >> g;
  for (int i = 0; i < g; i++) {
    cin >> tmp;
    y[tmp] = 1;
  }
  for (int i = 0; i < 1000000; i++) {
    int j = i % n;
    int k = i % m;
    if (x[j] == 1 || y[k] == 1) {
      x[j] = 1;
      y[k] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (x[i] == 0) {
      flag = 1;
      break;
    }
  }
  for (int i = 0; i < m; i++) {
    if (y[i] == 0) {
      flag = 1;
      break;
    }
  }
  if (flag == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
