#include <bits/stdc++.h>
using namespace std;
int n, m, b, g, k;
bool x[110], y[110];
bool res() {
  for (int i = 0; i <= 100 * m * n; ++i) {
    int _i = i % n, _j = i % m;
    if (x[_i])
      y[_j] = 1;
    else if (y[_j])
      x[_i] = 1;
  }
  for (int i = 0; i < n; ++i)
    if (!x[i]) return 0;
  for (int i = 0; i < m; ++i)
    if (!y[i]) return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  cin >> b;
  for (int i = 1; i <= b; ++i) {
    cin >> k;
    x[k] = 1;
  }
  cin >> g;
  for (int i = 1; i <= g; ++i) {
    cin >> k;
    y[k] = 1;
  }
  cout << (res() ? "Yes" : "No");
}
