#include <bits/stdc++.h>
using namespace std;
int n, m, x, y;
bool a[105], b[105];
int main() {
  scanf("%d %d", &n, &m);
  scanf("%d", &x);
  while (x--) {
    scanf("%d", &y);
    a[y] = 1;
  }
  scanf("%d", &y);
  while (y--) {
    scanf("%d", &x);
    b[x] = 1;
  }
  for (int i = 0; i < n * m * 10000; i++) {
    x = a[i % n], y = b[i % m];
    if (x || y)
      a[i % n] = b[i % m] = 1;
    else
      continue;
  }
  bool flag = 0;
  for (int i = 0; i < n; i++)
    if (!a[i]) flag = 1;
  for (int i = 0; i < m; i++)
    if (!b[i]) flag = 1;
  if (flag)
    puts("No");
  else
    puts("Yes");
  return 0;
}
