#include <bits/stdc++.h>
using namespace std;
int boy[200], girl[200];
int main() {
  int n, m, a, b, flag = 0, su;
  scanf("%d%d", &(n), &(m));
  cin >> a;
  for (int i = 0; i < a; i++) {
    cin >> su;
    su = su % n;
    boy[su] = 1;
  }
  cin >> b;
  for (int i = 0; i < b; i++) {
    cin >> su;
    su = su % m;
    girl[su] = 1;
  }
  int mm = m + n;
  int j = 0, k = 0;
  for (int i = 0; i < 10000; i++) {
    k = k % n;
    j = j % m;
    if (boy[k] == 1 || girl[j] == 1) boy[k] = girl[j] = 1;
    k++;
    j++;
  }
  for (int i = 0; i < n; i++) {
    if (boy[i] != 1) {
      cout << "No" << endl;
      flag = 1;
      break;
    }
  }
  if (flag == 0) {
    for (int i = 0; i < m; i++) {
      if (girl[i] != 1) {
        cout << "No" << endl;
        flag = 1;
        break;
      }
    }
  }
  if (flag == 0) cout << "Yes" << endl;
  return 0;
}
