#include <bits/stdc++.h>
using namespace std;
int arr[1000];
int brr[1000];
vector<long long> v;
vector<pair<int, int> > vp;
int main() {
  int n, m;
  cin >> n >> m;
  int b;
  cin >> b;
  for (int i = 0; i < b; i++) {
    int x;
    cin >> x;
    arr[x] = 1;
  }
  int g;
  cin >> g;
  for (int i = 0; i < g; i++) {
    int x;
    cin >> x;
    brr[x] = 1;
  }
  for (int i = 0; i < 10000000; i++) {
    int x = (i % n);
    int y = (i % m);
    int t = arr[x] | brr[y];
    arr[x] = t;
    brr[y] = t;
  }
  for (int i = 0; i < n; i++) {
    if (arr[i] == 0) {
      cout << "No";
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    if (brr[i] == 0) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}
