#include <bits/stdc++.h>
using namespace std;
const int MX = 2e2 + 2;
const int MOD = 1e9 + 7;
int a1[MX], a2[MX];
vector<int> gr[MX];
map<int, int> ma;
bool vis[MX], ha[MX];
void dfs(int x) {
  vis[x] = true;
  ha[x] = true;
  int sz = gr[x].size();
  for (int i = 0; i < sz; i++) {
    if (!vis[gr[x][i]]) dfs(gr[x][i]);
  }
}
int main() {
  int n, m, b, g;
  scanf("%d %d", &n, &m);
  int p1 = 0, p2 = 0;
  for (int i = 0; i < n * m; i++) {
    gr[p1].push_back(p2 + n);
    gr[n + p2].push_back(p1);
    p1 = (p1 + 1) % n;
    p2 = (p2 + 1) % m;
  }
  scanf("%d", &b);
  for (int i = 0; i < b; i++) {
    scanf("%d", &a1[i]);
    ma[a1[i]] = 1;
    if (!vis[a1[i]]) dfs(a1[i]);
  }
  scanf("%d", &g);
  for (int i = 0; i < g; i++) {
    scanf("%d", &a2[i]);
    ma[a2[i] + n] = 1;
    if (!vis[a2[i] + n]) dfs(a2[i] + n);
  }
  bool f = true;
  for (int i = 0; i < n + m; i++)
    if (!ha[i]) f = false;
  if (f)
    puts("Yes");
  else
    puts("No");
  return 0;
}
