#include <bits/stdc++.h>
using namespace std;
int x[1000];
int xx[1000];
int ans[1000];
int fa[10000];
void init(int n) {
  for (int i = 1; i <= n; ++i) fa[i] = i;
}
int f(int x) {
  if (fa[x] != x) fa[x] = f(fa[x]);
  return fa[x];
}
int main() {
  int n, m;
  while (scanf("%d%d", &n, &m) > 0) {
    init(n + m);
    memset(x, 0, sizeof(x));
    memset(xx, 0, sizeof(xx));
    memset(ans, 0, sizeof(ans));
    int b;
    scanf("%d", &b);
    for (int i = 0; i < b; ++i) {
      int t;
      scanf("%d", &t);
      x[t] = 1;
    }
    int g;
    scanf("%d", &g);
    for (int i = 0; i < g; ++i) {
      int t;
      scanf("%d", &t);
      xx[t] = 1;
    }
    for (int i = 0; i <= n * m; ++i) {
      int a = i % n;
      int b = i % m;
      if (f(a) != f(n + b)) {
        fa[f(a)] = f(n + b);
      }
    }
    for (int i = 0; i < n; ++i) {
      if (x[i] == 1) {
        ans[f(i)] = 1;
      }
    }
    for (int i = 0; i < m; ++i) {
      if (xx[i] == 1) {
        ans[f(i + n)] = 1;
      }
    }
    int ok = 1;
    for (int i = 0; i < n + m; ++i) {
      if (f(i) == i) {
        if (ans[i] == 0) {
          ok = 0;
          break;
        }
      }
    }
    if (ok) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
  }
}
