#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, b, g, vis[10005], bb[105] = {0}, gg[105] = {0};
  cin >> n >> m;
  cin >> b;
  for (int i = 0; i < b; i++) {
    int a;
    cin >> a;
    bb[a] = 1;
  }
  cin >> g;
  for (int i = 0; i < g; i++) {
    int a;
    cin >> a;
    gg[a] = 1;
  }
  int zz = 100 * m * n;
  for (int i = 0; i < zz; i++) {
    int a, c;
    a = i % n;
    c = i % m;
    if (bb[a] == 1 || gg[c] == 1) {
      bb[a] = 1;
      gg[c] = 1;
    }
  }
  int sum = 0;
  for (int i = 0; i < n; i++)
    if (bb[i] == 1) sum++;
  for (int i = 0; i < m; i++)
    if (gg[i] == 1) sum++;
  if (sum == m + n)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}
