#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, l, m, n, a1, b1, count, ans;
  while (scanf("%d %d", &n, &m) != EOF) {
    map<int, int> mp1, mp2;
    scanf("%d", &a1);
    for (i = 0; i < a1; i++) {
      scanf("%d", &l);
      mp1[l] = 1;
    }
    scanf("%d", &b1);
    for (i = 0; i < b1; i++) {
      scanf("%d", &l);
      mp2[l] = 1;
    }
    i = 0;
    count = a1 + b1;
    ans = n + m;
    while (1) {
      j = i % n;
      k = i % m;
      if (mp1[j] == 1 && (k + 1 <= m && mp2[k] == 0)) {
        count++;
        mp2[k] = 1;
      } else if ((j + 1 <= n && mp1[j] == 0) && mp2[k] == 1) {
        count++;
        mp1[j] = 1;
      }
      if (count == ans || i == 100000) break;
      i++;
    }
    if (count == ans)
      printf("Yes\n");
    else
      printf("No\n");
  }
  return 0;
}
