#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
bool stn[100100];
bool stm[100100];
int n, m;
int main() {
  cin >> n >> m;
  int a, b;
  cin >> a;
  for (int i = 0; i < a; i++) {
    cin >> b;
    stn[b] = 1;
  }
  cin >> a;
  for (int i = 0; i < a; i++) {
    cin >> b;
    stm[b] = 1;
  }
  for (int i = 0; i < 1000000; i++) {
    if (stn[i % n] == 1 || stm[i % m] == 1) {
      stn[i % n] = stm[i % m] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (stn[i] == 0) {
      printf("No\n");
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    if (stm[i] == 0) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
}
