#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  char c = getchar();
  bool f = 0;
  for (; c > '9' || c < '0'; f = c == '-', c = getchar())
    ;
  for (; c >= '0' && c <= '9'; x = (x << 1) + (x << 3) + c - '0', c = getchar())
    ;
  return f ? -x : x;
}
inline void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + 48);
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
void exgcd(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1, y = 0;
    return;
  }
  exgcd(b, a % b, x, y);
  long long tmp = x;
  x = y;
  y = tmp - a / b * y;
}
int inv(int a, int p) {
  long long x, y;
  exgcd(a, p, x, y);
  return (x + p) % p;
}
const int N = 2e5 + 5;
int d;
long long ans;
set<int> vis;
inline void Mn(long long &x, long long y) {
  if (x > y) x = y;
}
inline void Mx(long long &x, long long y) {
  if (x < y) x = y;
}
void work(const vector<int> &a, const vector<int> &b, int v, int n, int m) {
  vis.clear();
  static int p[N];
  static long long dis[N];
  int pcnt = 0;
  for (int i = 0, _y = a.size() - 1; i <= _y; ++i)
    p[pcnt++] = (long long)a[i] / d * v % n;
  for (int i = 0, _y = b.size() - 1; i <= _y; ++i)
    p[pcnt++] = (long long)b[i] / d * v % n;
  sort(p, p + pcnt);
  pcnt = unique(p, p + pcnt) - p;
  for (int i = 0, _y = pcnt - 1; i <= _y; ++i) dis[i] = 2e9;
  for (int i = 0, _y = a.size() - 1; i <= _y; ++i) {
    int x = (long long)a[i] / d * v % n;
    vis.insert(x);
    int y = lower_bound(p, p + pcnt, x) - p;
    Mn(dis[y], a[i]);
  }
  for (int i = 0, _y = b.size() - 1; i <= _y; ++i) {
    int x = (long long)b[i] / d * v % n;
    int y = lower_bound(p, p + pcnt, x) - p;
    Mn(dis[y], b[i]);
  }
  for (int k = 0, _y = 2 * pcnt - 1; k <= _y; ++k) {
    int i = (k + 1) % pcnt, j = k % pcnt;
    Mn(dis[i], dis[j] + (long long)(p[i] - p[j] + n) % n * m * d);
  }
  for (int i = 0, _y = pcnt - 1; i <= _y; ++i) {
    int j = (i + 1) % pcnt, x = (p[j] + n - 1) % n;
    if (vis.find(x) == vis.end())
      Mx(ans, dis[i] + (long long)(x - p[i] + n) % n * m * d);
  }
}
vector<int> a[N], b[N];
int n, m;
int main() {
  n = read(), m = read();
  d = gcd(n, m);
  n /= d, m /= d;
  if (d > 200000) return puts("-1"), 0;
  for (int ta = read(); ta--;) {
    int x = read();
    a[x % d].push_back(x);
  }
  for (int tb = read(); tb--;) {
    int x = read();
    b[x % d].push_back(x);
  }
  for (int i = 0, _y = d - 1; i <= _y; ++i)
    if (a[i].size() == 0 && b[i].size() == 0) return puts("-1"), 0;
  int inva = inv(n, m), invb = inv(m, n);
  for (int i = 0, _y = d - 1; i <= _y; ++i)
    work(a[i], b[i], invb, n, m), work(b[i], a[i], inva, m, n);
  printf("%lld\n", ans);
}
