#include <bits/stdc++.h>
using namespace std;
int n, m;
int b, g;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
bool happb[110];
bool happg[110];
vector<int> vib;
vector<int> vig;
bool check() {
  for (int i = 0; i < n; ++i) {
    if (!happb[i]) return false;
  }
  for (int j = 0; j < m; ++j) {
    if (!happg[j]) return false;
  }
  return true;
}
int main() {
  cin >> n >> m;
  cin >> b;
  for (int i = 0; i < b; ++i) {
    int tmp;
    cin >> tmp;
    vib.push_back(tmp);
    happb[tmp] = true;
  }
  cin >> g;
  for (int i = 0; i < g; ++i) {
    int tmp;
    cin >> tmp;
    vig.push_back(tmp);
    happg[tmp] = true;
  }
  int delta = gcd(n, m);
  for (int i = 0; i < n; ++i) {
    if (happb[i]) {
      bool flag = false;
      for (int j = 0; j < m; ++j) {
        if ((j - i) % delta == 0 && happg[j] != true) {
          flag = true;
          happg[j] = true;
        }
      }
      if (flag) {
        for (int k = 0; k < n; ++k) {
          if ((k - i) % delta == 0) {
            happb[k] = true;
          }
        }
      }
    }
  }
  for (int j = 0; j < m; ++j) {
    if (happg[j]) {
      bool flag = false;
      for (int i = 0; i < n; ++i) {
        if ((j - i) % delta == 0 && happb[i] != true) {
          flag = true;
          happb[i] = true;
        }
      }
      if (flag) {
        for (int k = 0; k < m; ++k) {
          if ((k - j) % delta == 0) {
            happg[k] = true;
          }
        }
      }
    }
  }
  if (check()) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
