#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int x;
  cin >> x;
  int b[100] = {0}, g[100] = {0};
  for (int i = 0; i < x; i++) {
    int y;
    cin >> y;
    b[y] = 1;
  }
  cin >> x;
  for (int i = 0; i < x; i++) {
    int y;
    cin >> y;
    g[y] = 1;
  }
  x = 0;
  while (x < 100000000) {
    if (b[x % n] == 1 || g[x % m] == 1) {
      b[x % n] = 1;
      g[x % m] = 1;
    }
    x++;
  }
  bool bl = false;
  for (int i = 0; i < n; i++) {
    if (b[i] == 0) bl = true;
  }
  for (int i = 0; i < m; i++) {
    if (g[i] == 0) bl = true;
  }
  if (bl)
    cout << "No"
         << "\n";
  else
    cout << "Yes"
         << "\n";
  return 0;
}
