#include <bits/stdc++.h>
using namespace std;
const int maxn = 111;
bool a[maxn], b[maxn], c[maxn], d[maxn];
int main() {
  int n, m, x, y, e, k;
  while (scanf("%d%d", &n, &m) != EOF) {
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    scanf("%d", &x);
    for (int i = 0; i < x; ++i) {
      scanf("%d", c + i);
      a[c[i]] = true;
    }
    scanf("%d", &y);
    for (int i = 0; i < y; ++i) {
      scanf("%d", d + i);
      b[d[i]] = true;
    }
    for (int i = 0; i < x; ++i) {
      for (int j = 0; j < m; ++j) {
        k = (j * n + c[i]) % m;
        if (!b[k]) {
          b[k] = 1;
        }
      }
    }
    for (int i = 0; i < m; ++i) {
      if (!b[i]) continue;
      for (int j = 0; j < n; ++j) {
        k = (j * m + i) % n;
        if (!a[k]) {
          a[k] = 1;
        }
      }
    }
    bool flag = true;
    for (int i = 0; i < n; ++i) {
      if (!a[i]) {
        flag = false;
        break;
      }
    }
    if (flag)
      puts("Yes");
    else
      puts("No");
  }
  return 0;
}
