#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
int n, m;
map<int, bool> mp1, mp2;
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    mp1.clear();
    mp2.clear();
    for (int i = 0; i < n; i++) mp1[i] = false;
    for (int i = 0; i < m; i++) mp2[i] = false;
    int x = 0, y = 0;
    scanf("%d", &x);
    for (int i = 0; i < x; i++) {
      int t = 0;
      scanf("%d", &t);
      mp1[t] = true;
    }
    scanf("%d", &y);
    for (int i = 0; i < y; i++) {
      int t = 0;
      scanf("%d", &t);
      mp2[t] = true;
    }
    bool ok1 = false, ok2 = false;
    for (int i = 0; i < 100000; i++) {
      ok1 = true, ok2 = true;
      int tot1 = i % n;
      int tot2 = i % m;
      if (mp1[tot1] || mp2[tot2]) {
        mp1[tot1] = true;
        mp2[tot2] = true;
      }
      for (int j = 0; j < n; j++) {
        if (!mp1[j]) {
          ok1 = false;
          break;
        }
      }
      for (int j = 0; j < m; j++) {
        if (!mp2[j]) {
          ok2 = false;
          break;
        }
      }
      if (ok1 && ok2) break;
    }
    if (ok1 && ok2)
      printf("Yes\n");
    else
      printf("No\n");
  }
}
