#include <bits/stdc++.h>
using namespace std;
vector<int> friends[105];
int r[210], p[210];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int n, m, i, j, b, g, c, u, h = 0;
  cin >> n >> m;
  int boys[n];
  memset(boys, 0, sizeof boys);
  int girls[m];
  memset(girls, 0, sizeof girls);
  cin >> b;
  h += b;
  while (b--) {
    cin >> c;
    boys[c] = 1;
  }
  cin >> b;
  h += b;
  while (b--) {
    cin >> c;
    girls[c] = 1;
  }
  u = n + m - h;
  for (i = 0; i <= 10000 * max(n, m); i++) {
    int b = (i % n);
    int g = (i % m);
    if ((boys[b] == 0 && girls[g] == 1) or (boys[b] == 1 && girls[g] == 0)) {
      u--;
      boys[b] = 1;
      girls[g] = 1;
    }
  }
  if (u <= 0)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}
