#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  bool schBoy[110] = {0}, schGirl[110] = {0};
  int b;
  cin >> b;
  while (b--) {
    int x;
    cin >> x;
    schBoy[x] = true;
  }
  int g;
  cin >> g;
  while (g--) {
    int x;
    cin >> x;
    schGirl[x] = true;
  }
  for (int i = 0; i < 10000000; i++) {
    int nb = i % n;
    int ng = i % m;
    if (schBoy[nb] || schGirl[ng]) schBoy[nb] = schGirl[ng] = true;
  }
  for (int i = 0; i < n; i++) {
    if (!schBoy[i]) {
      cout << "No";
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    if (!schGirl[i]) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}
