#include <bits/stdc++.h>
using namespace std;
int n, m, g;
bool a[101], b[101];
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  cin >> g;
  for (int i = 0; i < g; i++) {
    int x;
    cin >> x;
    a[x] = true;
  }
  cin >> g;
  for (int i = 0; i < g; i++) {
    int x;
    cin >> x;
    b[x] = true;
  }
  for (int i = 0; i < (n + 1) * (m + 1); i++) {
    if (a[i % n] || b[i % m]) {
      a[i % n] = true;
      b[i % m] = true;
    }
  }
  for (int i = 0; i < n; i++) {
    if (!a[i]) {
      cout << "No\n";
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    if (!b[i]) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
}
