#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m, b, g;
  cin >> n >> m;
  vector<int> muski(n), zene(m);
  cin >> b;
  for (int i = 0; i < b; ++i) {
    int t;
    cin >> t;
    muski[t] = 1;
  }
  cin >> g;
  for (int i = 0; i < g; ++i) {
    int t;
    cin >> t;
    zene[t] = 1;
  }
  for (int i = 0; i < 2 * n * m; ++i)
    if ((muski[i % n]) || (zene[i % m])) {
      muski[i % n] = 1;
      zene[i % m] = 1;
    }
  int t = 1;
  for (int i = 0; i < n; ++i)
    if (muski[i] == 0) t = 0;
  for (int i = 0; i < m; ++i)
    if (zene[i] == 0) t = 0;
  if (t)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}
