#include <bits/stdc++.h>
using namespace std;
bool A[102][102], visited[2 * 102];
int B[2][102];
int DFS(int u, int n, int m) {
  int c = 1, i;
  visited[u] = true;
  if (u < 100) {
    for (i = 0; i < m; ++i)
      if (A[u][i] && !visited[100 + i]) c += DFS(100 + i, n, m);
  } else
    for (i = 0; i < n; ++i)
      if (A[i][u - 100] && !visited[i]) c += DFS(i, n, m);
  return c;
}
bool solve(int n, int m, int n1, int n2) {
  int a = 0, b = 0, c = 0, i;
  while (!A[a][b]) {
    A[a][b] = true;
    a = (a + 1) % n, b = (b + 1) % m;
  }
  for (i = 0; i < n1; ++i)
    if (!visited[B[0][i]]) c += DFS(B[0][i], n, m);
  for (i = 0; i < n2; ++i)
    if (!visited[100 + B[1][i]]) c += DFS(100 + B[1][i], n, m);
  return c == n + m;
}
int main() {
  int n, m, h1, h2, i;
  scanf("%d %d", &n, &m);
  scanf("%d", &h1);
  for (i = 0; i < h1; ++i) scanf("%d", &B[0][i]);
  scanf("%d", &h2);
  for (i = 0; i < h2; ++i) scanf("%d", &B[1][i]);
  puts(solve(n, m, h1, h2) ? "Yes" : "No");
  return 0;
}
