#include <bits/stdc++.h>
template <class T>
T sq(T n) {
  return n * n;
}
template <class T>
T getmax(T a, T b) {
  return (a > b ? a : b);
}
template <class T>
T getmin(T a, T b) {
  return (a < b ? a : b);
}
template <class T>
void setmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
void setmin(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
T gcd(T a, T b) {
  return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
  return ((a * b) / gcd(a, b));
}
template <class T>
T power(T n, T p) {
  if (p == 0) return 1;
  return ((p == 1) ? n : (n * power(n, p - 1)));
}
using namespace std;
int main() {
  int i, j, k, n, m;
  while (cin >> n >> m) {
    map<int, bool> mp;
    int bcnt = 0, gcnt = 0;
    int bb, gg;
    cin >> bb;
    for (i = 0; i < bb; i++) {
      cin >> k;
      mp[k] = true;
    }
    cin >> gg;
    for (i = 0; i < gg; i++) {
      cin >> k;
      mp[k] = true;
    }
    for (i = 0; i < 10000; i++) {
      int b = i % n;
      int g = i % m;
      if (mp[b] == true || mp[g] == true) {
        mp[b] = true;
        mp[g] = true;
      }
    }
    for (i = 0; i < n; i++) {
      if (mp[i] == true) bcnt++;
    }
    for (i = 0; i < m; i++) {
      if (mp[i] == true) gcnt++;
    }
    if (bcnt == n && gcnt == m)
      cout << "Yes\n";
    else
      cout << "No\n";
  }
  return 0;
}
