#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0) return a;
  if (a < b) swap(a, b);
  return gcd(b, a % b);
}
int main() {
  int boys_count, girls_count;
  cin >> boys_count >> girls_count;
  vector<int> boys(boys_count, 0);
  vector<int> girls(girls_count, 0);
  int happy_boys_count, happy_girls_count;
  cin >> happy_boys_count;
  for (int i = 0; i < happy_boys_count; i++) {
    int index;
    cin >> index;
    boys[index] = 1;
  }
  cin >> happy_girls_count;
  for (int i = 0; i < happy_girls_count; i++) {
    int index;
    cin >> index;
    girls[index] = 1;
  }
  int day = 0;
  while ((happy_boys_count != boys_count || happy_girls_count != girls_count) &&
         day < girls_count * boys_count * 10) {
    if (boys[day % boys_count] == 1 && girls[day % girls_count] == 0) {
      girls[day % girls_count] = 1;
      happy_girls_count++;
    } else if (boys[day % boys_count] == 0 && girls[day % girls_count] == 1) {
      boys[day % boys_count] = 1;
      happy_boys_count++;
    }
    day++;
  }
  if (happy_boys_count == boys_count && happy_girls_count == girls_count)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
