#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";

}