#include <iostream>
#include <cstdlib>
#include <set>
using namespace std;
set< int > happyB;
set< int > happyG;
int main(){
int x;
int B, G;
int g, b;
bool *boys;
bool *girls;
cin >> B >> G;
boys= new bool[B];
girls= new bool[G];
cin >> b;
while( b-- ){
cin >> x;
boys[x]= true;
}
cin >> g;
while( g-- ){
cin >> x;
girls[x]= true;
}
for( int i=0; i<B*G; i++ ){
int Gindex= i%G;
int Bindex= i%B;
if( boys[Bindex]== true || girls[Gindex]== true ){
boys[Bindex]== true;
girls[Gindex]== true;
happyB.insert( Bindex );
happyG.insert( Gindex );
if( happyG.size()== G && happyB.size()== B ){
cout << "Yes";
return 0;
}
}
}
cout << "No";
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGxpYj4KI2luY2x1ZGUgPHNldD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzZXQ8IGludCA+IGhhcHB5QjsKc2V0PCBpbnQgPiBoYXBweUc7CgppbnQgbWFpbigpewoKCWludCB4OwoJaW50IEIsIEc7CglpbnQgZywgYjsKCWJvb2wgKmJveXM7Cglib29sICpnaXJsczsKCgljaW4gPj4gQiA+PiBHOwoKCWJveXM9IG5ldyBib29sW0JdOwoJZ2lybHM9IG5ldyBib29sW0ddOwoKCWNpbiA+PiBiOwoKCXdoaWxlKCBiLS0gKXsKCgkJY2luID4+IHg7CgkJYm95c1t4XT0gdHJ1ZTsKCX0KCgljaW4gPj4gZzsKCgl3aGlsZSggZy0tICl7CgoJCWNpbiA+PiB4OwoJCWdpcmxzW3hdPSB0cnVlOwoJfQoKCglmb3IoIGludCBpPTA7IGk8QipHOyBpKysgKXsKCgkJaW50CUdpbmRleD0gaSVHOwoJCWludCBCaW5kZXg9IGklQjsKCgkJaWYoIGJveXNbQmluZGV4XT09IHRydWUgfHwgZ2lybHNbR2luZGV4XT09IHRydWUgKXsKCgkJCWJveXNbQmluZGV4XT09IHRydWU7CgkJCWdpcmxzW0dpbmRleF09PSB0cnVlOwoKCQkJaGFwcHlCLmluc2VydCggQmluZGV4ICk7CgkJCWhhcHB5Ry5pbnNlcnQoIEdpbmRleCApOwoKCQkJaWYoIGhhcHB5Ry5zaXplKCk9PSBHICYmIGhhcHB5Qi5zaXplKCk9PSBCICl7CgoJCQkJY291dCA8PCAiWWVzIjsKCQkJCXJldHVybiAwOwoJCQl9CgkJfQoKCX0KCgljb3V0IDw8ICJObyI7Cgp9