#include <bits/stdc++.h>
using namespace std;
long long int n, m, b, i, g, k, boy[105], girl[105];
int main() {
  cin >> n >> m;
  cin >> b;
  for (i = 0; i < b; i++) {
    cin >> k;
    boy[k] = 1;
  }
  cin >> g;
  for (i = 0; i < g; i++) {
    cin >> k;
    girl[k] = 1;
  }
  long long int t = 2;
  while (t) {
    for (i = 0; i < n * m; i++) {
      girl[i % m] = boy[i % n] = (girl[i % m] || boy[i % n]);
    }
    t--;
  }
  for (i = 0; i < n; i++) {
    if (boy[i] == 0) {
      cout << "No";
      return 0;
    }
  }
  for (i = 0; i < m; i++) {
    if (girl[i] == 0) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}
