#include <bits/stdc++.h>
using namespace std;
bool markg[110], markb[110];
int main() {
  int m, n, a, b;
  cin >> m >> n >> a;
  for (int i = 0; i < a; i++) {
    int t;
    cin >> t;
    markb[t] = true;
  }
  cin >> b;
  for (int i = 0; i < b; i++) {
    int t;
    cin >> t;
    markg[t] = true;
  }
  for (int i = 0; i <= 1000000; i++) {
    if (markb[i % m] or markg[i % n]) {
      markb[i % m] = true;
      markg[i % n] = true;
    }
  }
  for (int i = 0; i < m; i++)
    if (!markb[i]) {
      cout << "No";
      return 0;
    }
  for (int i = 0; i < n; i++)
    if (!markg[i]) {
      cout << "No";
      return 0;
    }
  cout << "Yes";
}
