#include <bits/stdc++.h>
using namespace std;
int n, m, x, y;
bool haha, happy[330], vis[330];
vector<int> adj[330];
int fpb(int a, int b) { return (b == 0) ? a : fpb(b, a % b); }
void dfs(int x) {
  if (happy[x]) haha = true;
  vis[x] = true;
  for (int i = 0; i < (int)adj[x].size(); i++) {
    if (!vis[adj[x][i]]) dfs(adj[x][i]);
  }
}
int main() {
  scanf("%d %d", &n, &m);
  scanf("%d", &x);
  for (int i = 1; i <= x; i++) {
    scanf("%d", &y);
    happy[y] = true;
  }
  scanf("%d", &x);
  for (int i = 1; i <= x; i++) {
    scanf("%d", &y);
    happy[y + n] = true;
  }
  x = n * m / fpb(n, m);
  for (int i = 0; i < x; i++) {
    adj[i % n].push_back((i % m) + n);
    adj[(i % m) + n].push_back(i % n);
  }
  for (int i = 0; i < n + m; i++) {
    if (!vis[i]) {
      haha = false;
      dfs(i);
      if (!haha) {
        puts("No");
        return 0;
      }
    }
  }
  puts("Yes");
}
