#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b > a)
    return gcd(b, a);
  else if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
int main() {
  int n, m, k, i, j;
  cin >> n >> m >> k;
  int x = gcd(n, m);
  bool arr[x];
  fill(arr, arr + x, false);
  for (i = 0; i < k; i++) {
    cin >> j;
    arr[j % x] = true;
  }
  cin >> k;
  for (i = 0; i < k; i++) {
    cin >> j;
    arr[j % x] = true;
  }
  for (i = 0; i < x; i++)
    if (!arr[i]) break;
  cout << (find(arr, arr + x, false) == (arr + x) ? "Yes" : "No") << endl;
  return 0;
}
