#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int n, m;
bool bh[105], gh[105];
int main() {
  cin >> n >> m;
  int b;
  cin >> b;
  for (int i = 1; i <= b; i++) {
    int x;
    scanf("%d", &x);
    bh[x] = true;
  }
  int g;
  cin >> g;
  for (int i = 1; i <= g; i++) {
    int x;
    scanf("%d", &x);
    gh[x] = true;
  }
  int t1 = 0, t2 = 0;
  int T = 1e8;
  while (b != n || g != m) {
    if (!T) break;
    T -= 1;
    if (bh[t1] && !gh[t2]) {
      gh[t2] = true;
      g += 1;
    } else if (!bh[t1] && gh[t2]) {
      bh[t1] = true;
      b += 1;
    }
    t1++;
    if (t1 == n) t1 = 0;
    t2++;
    if (t2 == m) t2 = 0;
  }
  if (b == n && g == m)
    printf("Yes\n");
  else
    printf("No\n");
}
