#include <bits/stdc++.h>
using namespace std;
const int maxn = int(1e9 + 9);
ifstream fin("input.txt");
ofstream fout("ofput.txt");
using namespace std;
bool rev(long long l, long long r) { return l > r; }
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<short> b(n, 0);
  vector<short> g(m, 0);
  int buf;
  cin >> buf;
  int rb = buf;
  for (int i = 0; i < buf; i++) {
    int c;
    cin >> c;
    b[c] = 1;
  }
  cin >> buf;
  int rg = buf;
  for (int i = 0; i < buf; i++) {
    int c;
    cin >> c;
    g[c] = 1;
  }
  for (int i = 0; i <= n * m * (n + m); i++) {
    if (b[i % n] == 1 && g[i % m] == 0)
      g[i % m] = 1, rg++;
    else if (b[i % n] == 0 && g[i % m] == 1)
      b[i % n] = 1, rb++;
  }
  cout << (rb == n && rg == m ? "Yes" : "No");
  return 0;
}
