#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int an[101], am[101];
  cin >> n >> m;
  for (int i = 0; i < n; i++) an[i] = 0;
  for (int i = 0; i < m; i++) am[i] = 0;
  int b, g;
  cin >> b;
  for (int i = 0; i < b; i++) {
    int k;
    cin >> k;
    an[k] = 1;
  }
  cin >> g;
  for (int i = 0; i < g; i++) {
    int k;
    cin >> k;
    am[k] = 1;
  }
  for (int i = 0; i <= 1000000; i++) {
    an[i % n] = (an[i % n] | am[i % m]);
    am[i % m] = (an[i % n] | am[i % m]);
  }
  bool ok = true;
  for (int i = 0; i < n; i++)
    if (an[i] == 0) ok = false;
  for (int i = 0; i < m; i++)
    if (am[i] == 0) ok = false;
  if (ok)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}
