#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 5;
const int mod = 1000000007;
int b[N], g[N];
map<int, map<int, int> > mp;
int main() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  int x;
  scanf("%d", &x);
  for (int i = 0; i < x; i++) {
    int k;
    scanf("%d", &k);
    b[k]++;
  }
  int ans = n + m - x;
  scanf("%d", &x);
  for (int i = 0; i < x; i++) {
    int k;
    scanf("%d", &k);
    g[k]++;
  }
  ans -= x;
  while (ans) {
    for (int i = 0, j = 0; ans; i++, j++) {
      if (mp[i % n][j % m] == 3) {
        cout << "No\n";
        return 0;
      }
      ans -= ((!b[i % n]) + (!g[j % m])) % 2;
      int temp = b[i] + g[i];
      b[i % n] = max(b[i % n], g[j % m]);
      g[j % m] = b[i % n];
      mp[i % n][j % m]++;
    }
  }
  cout << "Yes\n";
  return 0;
}
