#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<bool> b(n, false), g(m, false);
  int cnt;
  cin >> cnt;
  for (int i = 0; i < (int)cnt; i++) {
    int boyNumber;
    cin >> boyNumber;
    b[boyNumber] = true;
  }
  cin >> cnt;
  for (int i = 0; i < (int)cnt; i++) {
    int girlNumber;
    cin >> girlNumber;
    g[girlNumber] = true;
  }
  for (int i = 0; i < (int)100000; i++) {
    int boy = i % n;
    int girl = i % m;
    bool isChange = b[boy] ^ g[girl];
    b[boy] = b[boy] || isChange;
    g[girl] = g[girl] || isChange;
  }
  bool isOk = true;
  for (int i = 0; i < (int)n; i++)
    if (!b[i]) isOk = false;
  for (int i = 0; i < (int)m; i++)
    if (!g[i]) isOk = false;
  if (isOk)
    printf("Yes");
  else
    printf("No");
  return 0;
}
