#include <bits/stdc++.h>
using namespace std;
bool man[110];
bool woman[110];
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int b;
  cin >> b;
  for (int i = 0; i < b; i++) {
    int t;
    cin >> t;
    man[t] = 1;
  }
  int g;
  cin >> g;
  for (int i = 0; i < g; i++) {
    int t;
    cin >> t;
    woman[t] = 1;
  }
  if (b == 0 && g == 0) {
    cout << "No\n";
    return 0;
  }
  for (int i = 0; i < 11000; i++) {
    if (man[i % n]) {
      woman[i % m] = 1;
    }
    if (woman[i % m]) {
      man[i % n] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (man[i] == 0) {
      cout << "No\n";
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    if (woman[i] == 0) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  return 0;
}
