#include <bits/stdc++.h>
using namespace std;
const int N = 105;
char a[N], b[N];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  int x;
  cin >> x;
  for (int i = 0; i < x; i++) {
    int p;
    cin >> p;
    a[p] = 1;
  }
  int y;
  cin >> y;
  for (int i = 0; i < y; i++) {
    int q;
    cin >> q;
    b[q] = 1;
  }
  int mx = n * n * m * m;
  for (int i = 0; i < mx; i++) {
    int p = i % n, q = i % m;
    if (a[p]) b[q] = 1;
    if (b[q]) a[p] = 1;
  }
  for (int i = 0; i < n; i++) {
    if (!a[i]) return cout << "No", 0;
  }
  for (int i = 0; i < m; i++) {
    if (!b[i]) return cout << "No", 0;
  }
  cout << "Yes";
}
