#include <bits/stdc++.h>
using namespace std;
int n, m;
void spreadHappiness(vector<vector<bool>>& isHappy) {
  int boy, girl;
  for (int i = 0; i < (n + m) * n * m; i++) {
    boy = i % n;
    girl = i % m;
    if (isHappy[0][boy] != isHappy[1][girl]) {
      isHappy[1][girl] = true;
      isHappy[0][boy] = true;
    }
  }
}
using namespace std;
int main() {
  cin >> n >> m;
  vector<vector<bool>> isHappy;
  isHappy.push_back(vector<bool>(n, false));
  isHappy.push_back(vector<bool>(m, false));
  int boy = 0, girl = 1;
  vector<bool> isHappyGirl(m, false);
  int nHappyBoy, nHappyGirl, iHappy, iFirstPartner, iPartner, iMeeting;
  cin >> nHappyBoy;
  for (int i = 0; i < nHappyBoy; i++) {
    cin >> iHappy;
    isHappy[boy][iHappy] = true;
  }
  cin >> nHappyGirl;
  for (int i = 0; i < nHappyGirl; i++) {
    cin >> iHappy;
    isHappy[girl][iHappy] = true;
  }
  spreadHappiness(isHappy);
  cout << ((find(isHappy[boy].begin(), isHappy[boy].end(), false) ==
                isHappy[boy].end() &&
            find(isHappy[girl].begin(), isHappy[girl].end(), false) ==
                isHappy[girl].end())
               ? "Yes"
               : "No");
}
