#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, b, g;
  cin >> n >> m >> b;
  int hb[n];
  for (int i = 0; i < n; i++) hb[i] = 0;
  for (int i = 0; i < b; i++) {
    int x;
    cin >> x;
    hb[x] = 1;
  }
  cin >> g;
  int hg[m];
  for (int i = 0; i < m; i++) hg[i] = 0;
  for (int i = 0; i < g; i++) {
    int x;
    cin >> x;
    hg[x] = 1;
  }
  for (int i = 0; i <= 2 * n * m; i++) {
    if (hg[i % m] == 1 || hb[i % n] == 1) {
      hg[i % m] = 1;
      hb[i % n] = 1;
    }
  }
  int flag = 0;
  for (int i = 0; i < n; i++) {
    if (hb[i] == 0) {
      flag = 1;
      cout << "No" << endl;
      break;
    }
  }
  cout << endl;
  if (flag == 0) {
    for (int i = 0; i < m; i++) {
      if (hg[0] == 0) {
        flag = 1;
        cout << "No" << endl;
        break;
      }
    }
  }
  if (flag == 0) cout << "Yes" << endl;
  return 0;
}
