#include <bits/stdc++.h>
using namespace std;
int b[105], g[105];
int main() {
  int n, m;
  cin >> n >> m;
  int x;
  cin >> x;
  while (x--) {
    int p;
    cin >> p;
    b[p] = 1;
  }
  int y;
  cin >> y;
  while (y--) {
    int q;
    cin >> q;
    g[q] = 1;
  }
  for (int i = 0; i <= 1000000; i++) {
    if (b[i % n] == 1)
      g[i % m] = 1;
    else if (g[i % m] == 1)
      b[i % n] = 1;
  }
  int xx = 0;
  for (int i = 0; i < n; i++) xx += b[i];
  for (int i = 0; i < m; i++) xx += g[i];
  if (xx != m + n)
    puts("NO");
  else
    puts("YES");
  return 0;
}
