#include<bits/stdc++.h>
using namespace std;
/*-----------------------------------------MACROS--------------------------*/
#define inf 1000000007
#define loop(i,n) for(int i=0;i<(int)n;i++)
#define iloop(i,n) for(int i=n;i>=1;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define sz(a) int((a).size())
#define pb push_back
#define pf pop_front
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define EPS 1e-9
#define ff first
#define ss second
#define gi(n) scanf("%d",&n)
#define gl(n) cin >> n
#define pi(n) printf("%d",n)
#define pl(n) cout << n
#define ps printf(" ")
#define pn printf("\n")
#define dg(n,s); printf("%s %d",s,n)
#define mp make_pair
#define UNVISITED -1
#define EXPLORED 0
#define VISITED 1
/*--------------------------------------------typedefs-------------------------*/
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector< vi > vvi;
typedef pair<int,int> ii;
typedef vector< ii > vii;
typedef long long ll;
typedef vector< ll > vll;
/*-----------------------------------Graph helpers------------------*/
int x_disp[]={-1,0,1,0};
int y_disp[]={0,-1,0,1};
int main()
{
ios_base::sync_with_stdio(false);
int n,m;
cin>>n>>m;
vector<int>boy(n,0),girl(m,0);
int b,g;
cin>>b;
for(int i=0;i<b;i++)
{
int temp;
cin>>temp;
boy[i]=1;
}
cin>>g;
for(int i=0;i<g;i++)
{
int temp;
cin>>temp;
girl[i]=1;
}
for(int i=0;i<1000000;i++)
{
if(boy[i%n] || girl[i%m])
boy[i%n]=girl[i%m]=1;
}
if(find(all(boy),0)==boy.end() && find(all(girl),0)==girl.end())
cout<<"Yes";
else
cout<<"No";
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKLyotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLU1BQ1JPUy0tLS0tLS0tLS0tLS0tL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