#include <bits/stdc++.h>
using namespace std;
bool boys[100], girls[100];
int main() {
  int n, m;
  cin >> n >> m;
  int b;
  cin >> b;
  int temp;
  for (int i = 0; i < b; i++) {
    cin >> temp;
    boys[temp] = true;
  }
  int g;
  cin >> g;
  for (int i = 0; i < g; i++) {
    cin >> temp;
    girls[temp] = true;
  }
  for (int i = 0; i < n * m + 5000; i++) {
    if (girls[i % m] || boys[i % n]) {
      girls[i % m] = true;
      boys[i % n] = true;
    }
  }
  for (int i = 0; i < n; i++) {
    if (!boys[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    if (!girls[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}
