#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, l, cnt, ans, c, a[105], b[105], d[210], x;
int main() {
  cin >> n >> m;
  for (cin >> c, i = 0; i < c; i++) cin >> x, a[x] = 1;
  for (cin >> c, i = 0; i < c; i++) cin >> x, b[x] = 1;
  for (i = 0; i < 1e6; i++)
    if (a[i % n] == 1 || b[i % m] == 1) a[i % n] = 1, b[i % m] = 1;
  for (i = 0; i < n; i++) cnt += (a[i] == 0);
  for (i = 0; i < m; i++) cnt += (b[i] == 0);
  cout << (cnt == 0 ? "Yes" : "No");
}
