#include <bits/stdc++.h>
using namespace std;
int a[150], b[150];
int main() {
  int n, m;
  int pos1, pos2;
  cin >> n >> m;
  int t;
  int number1, number2;
  cin >> number1;
  while (number1--) {
    cin >> t;
    a[t] = 1;
  }
  cin >> number2;
  while (number2--) {
    cin >> t;
    b[t] = 1;
  }
  for (int i = 0; i < 1000000; i++) {
    pos1 = i % n;
    pos2 = i % m;
    if (a[pos1] == 1) b[pos2] = 1;
    if (b[pos2] == 1) a[pos1] = 1;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    if (b[i] == 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}
