#include <bits/stdc++.h>
using namespace std;
int n, m;
int cna, cnb;
bool isha[108];
bool ishb[108];
bool vis[108];
int main() {
  cin >> n >> m;
  cin >> cna;
  int tmp;
  for (int i = 0; i < cna; i++) {
    scanf("%d", &tmp);
    isha[tmp] = 1;
  }
  cin >> cnb;
  for (int i = 0; i < cnb; i++) {
    scanf("%d", &tmp);
    ishb[tmp] = 1;
  }
  for (int i = 0; i < n; i++) {
    if (!isha[i]) continue;
    int x = i % m;
    vis[x] = 1;
    ishb[x] = 1;
    tmp = 0;
    while (true) {
      tmp = (tmp + n) % m;
      x = (i + tmp) % m;
      if (vis[x]) break;
      vis[x] = 1;
      ishb[x] = 1;
    }
  }
  memset(vis, 0, sizeof vis);
  for (int i = 0; i < m; i++) {
    if (!ishb[i]) continue;
    int x = i % n;
    isha[x] = 1;
    vis[x] = 1;
    tmp = 0;
    while (true) {
      tmp = (tmp + m) % n;
      x = (i + tmp) % n;
      if (vis[x]) break;
      vis[x] = 1;
      isha[x] = 1;
    }
  }
  memset(vis, 0, sizeof vis);
  for (int i = 0; i < n; i++) {
    if (!isha[i]) continue;
    int x = i % m;
    vis[x] = 1;
    ishb[x] = 1;
    tmp = 0;
    while (true) {
      tmp = (tmp + n) % m;
      x = (i + tmp) % m;
      if (vis[x]) break;
      vis[x] = 1;
      ishb[x] = 1;
    }
  }
  memset(vis, 0, sizeof vis);
  for (int i = 0; i < m; i++) {
    if (!ishb[i]) continue;
    int x = i % n;
    isha[x] = 1;
    vis[x] = 1;
    tmp = 0;
    while (true) {
      tmp = (tmp + m) % n;
      x = (i + tmp) % n;
      if (vis[x]) break;
      vis[x] = 1;
      isha[x] = 1;
    }
  }
  bool flag = 0;
  for (int i = 0; i < n; i++) {
    if (!isha[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    if (!ishb[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}
