#include <bits/stdc++.h>
using namespace std;
int a[200], b[200];
int main() {
  long long i, j, k, l, m, n;
  cin >> n >> m;
  cin >> j;
  for (i = 0; i < j; i++) {
    cin >> k;
    a[k] = 1;
  }
  cin >> k;
  for (i = 0; i < k; i++) {
    cin >> j;
    b[j] = 1;
  }
  for (i = 0; i <= 10000; i++) {
    if (a[i % n] + b[i % m]) a[i % n] = b[i % m] = 1;
  }
  long long temp = 0;
  for (i = 0; i < n; i++) temp += a[i];
  for (i = 0; i < m; i++) temp += b[i];
  if (temp < m + n)
    cout << "No";
  else
    cout << "Yes";
}
