#include <bits/stdc++.h>
using namespace std;
bool g[1000], b[1000];
int main() {
  int n, m;
  cin >> n >> m;
  int n1;
  cin >> n1;
  for (int i = 0; i < n1; i++) {
    int x;
    cin >> x;
    b[x] = true;
  }
  int m1;
  cin >> m1;
  for (int i = 0; i < m1; i++) {
    int y;
    cin >> y;
    g[y] = true;
  }
  int i = 0;
  bool ok = false;
  while (true) {
    if (b[i % n] == true || g[i % m] == true) {
      b[i % n] = true;
      g[i % m] = true;
    }
    if (i >= 10000) break;
    bool x = true, y = true;
    for (int i = 0; i < n; i++)
      if (b[i] == false) x = false;
    for (int i = 0; i < m; i++)
      if (g[i] == false) y = false;
    if (x == true && y == true) {
      ok = true;
      break;
    }
    i++;
  }
  if (ok == true)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}
