#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  return (!b ? a : gcd(b, a % b));
}
long long int lcm(long long int a, long long int b) {
  return (a * b) / gcd(a, b);
}
int arr[100005];
int ans(int n, int y, int k) {
  int tmp;
  int c = 0;
  for (int j = 1; j * j <= n; ++j) {
    if (n % j == 0) {
      tmp = n / j;
      if (arr[j] < k - y) {
        c++;
      }
      if (arr[tmp] < k - y && j != tmp) c++;
      arr[j] = arr[tmp] = k;
    }
  }
  return c;
}
int main() {
  int n, m, x = 0, y = 0, a, b, boys[102], girls[102];
  scanf("%d%d", &n, &m);
  memset(boys, 0, sizeof(boys));
  memset(girls, 0, sizeof(girls));
  scanf("%d", &b);
  int t;
  for (int i = 0; i <= b - 1; ++i) {
    scanf("%d", &t);
    boys[t] = 1;
  }
  scanf("%d", &a);
  for (int i = 0; i <= a - 1; ++i) {
    scanf("%d", &t);
    girls[t] = 1;
  }
  int i = 0;
  int c = 0;
  int diff = 0;
  int olddiff = 0;
  while (true) {
    x = i % n;
    y = i % m;
    if (!x && !y) {
      c++;
      if (c > 1) {
        if (diff == olddiff) break;
        olddiff = diff;
      }
    }
    t = (boys[x] | girls[y]);
    diff += (t != boys[x] || t != girls[y]);
    girls[y] = boys[x] = t;
    i++;
  }
  printf((count(boys, boys + n, 1) == n && count(girls, girls + m, 1) == m)
             ? "Yes"
             : "No");
}
