#include<bits/stdc++.h>
/*
*/

using namespace std;


//??????????????????0??¨???????¢?????????????????????¨??????
#define DEBUG 0

class D3 {
public:
	double X, Y, Z, EPS;

	D3( double, double, double );
	bool operator== ( D3 Partner );
	bool operator==( double );
	D3 operator*( double );
	D3 operator/( double );

	friend ostream& operator<<( ostream& os, const D3& );
};

class Point :private D3 {
public:
	Point( double, double, double );
	double getX();
	double getY();
	double getZ();

	bool operator== ( Point );
	bool operator<( Point );
	bool operator>( Point );
	friend bool operator<( const Point&, const Point& );
	friend bool operator>( const Point&, const Point& );
	double S_point( Point, Point );
	double V_point( Point, Point, Point );

	friend ostream& operator<<( ostream& os, const Point& );
};

class Vec {
private:
	Point SP;//Starting Point ?§????
	D3 D;//Direction ??????

	Vec( D3 Direction_, Point SP_ );
public:
	Vec( double x_, double y_, double z_, Point );
	Vec operator+( Vec Partner );
	Vec operator*( Vec Partner );
	Vec operator*( double ld );
	Vec operator-( Vec Partner );
	Vec operator/( Vec Partner );
	Vec operator/( double );
	bool operator== ( Vec );
	bool operator==( double );
	Vec Cross_product( Vec );
	double Inner_product( Vec );
	Vec( Point A, Point B );
	Point getSP();
	Point getGP();
	D3 getD();
	double length();
	Vec Unit_vec();
	Vec Inverse_vec();
	Vec Reverse_vec();
	bool Vertical( Vec );
	bool Parallel( Vec );
	bool isIntersection( Vec );
	Point IntersectionPoint( Vec );
	bool onVecPoint( Point );
	double S_vec( Vec );
	double V_vec( Vec, Vec );

	friend ostream& operator<<( ostream& os, const Vec& );

};


//D3

D3::D3( double x_ = 0.0L, double y_ = 0.0L, double z_ = 0.0L ) {
	X = x_;
	Y = y_;
	Z = z_;
	EPS = 1e-9L;
}

bool D3::operator== ( D3 Partner ) {
	return abs( X - Partner.X ) < EPS&&abs( Y - Partner.Y ) < EPS&&abs( Z - Partner.Z ) < EPS;
}

bool D3::operator==( double ld ) {
	return ( *this ) == D3();
}

D3 D3::operator*( double ld ) {
	return D3( X*ld, Y*ld, Z*ld );
}

D3 D3::operator/( double ld ) {
	return  *this*( ld*-1.L );
}

ostream& operator<<( ostream& os, const D3& d ) {
	if( DEBUG ) {
		os << "D3" << endl;
		os << "X:" << d.X << endl;
		os << "Y:" << d.Y << endl;
		os << "Z:" << d.Z << endl;
	}
	return os;
}


//Point

Point::Point( double x_ = 0.0L, double y_ = 0.0L, double z_ = 0.0L ) {
	X = x_;
	Y = y_;
	Z = z_;
}

//x??§?¨??????????
double Point::getX() {
	return X;
}

//y??§?¨??????????
double Point::getY() {
	return Y;
}

//z??§?¨??????????
double Point::getZ() {
	return Z;
}

bool Point::operator== ( Point Partner ) {
	return D3( *this ) == D3( Partner );
}
bool Point::operator<( Point Partner ) {
	if( ( *this ).getX() != Partner.getX() ) {
		return ( *this ).getX() < Partner.getX();
	}
	if( ( *this ).getY() != Partner.getY() ) {
		return ( *this ).getY() < Partner.getY();
	}
	return ( *this ).getZ() < Partner.getZ();

}
bool Point::operator>( Point Partner ) {
	return Partner < ( *this );
}
//??????????????¢???????±???????
double Point::S_point( Point B, Point C ) {
	Vec AB( *this, B ), AC( *this, C );
	return AB.S_vec( AC );
}

//??????????????????????±???????
double Point::V_point( Point B, Point C, Point D ) {
	return Vec( ( *this ), B ).V_vec( Vec( ( *this ), C ), Vec( ( *this ), D ) );
}


ostream & operator<<( ostream & os, const Point &p ) {
	if( DEBUG ) {
		os << "Point" << endl;
		os << "X:" << p.X << endl;
		os << "Y:" << p.Y << endl;
		os << "Z:" << p.Z << endl;
	}
	return os;
}

bool operator<( const Point& p1, const Point& p2 ) {
	if( p1.X == p2.X ) {
		if( p1.Y == p2.Y ) {
			return p1.Z < p2.Z;
		}
		return p1.Y < p2.Y;
	}
	return p1.X < p2.X;
}

bool operator>( const Point& p1, const Point& p2 ) {
	return p2 < p1;
}


//Vec

//??????????????¨?§???????????????????????????????
Vec::Vec( D3 Direction_, Point SP_ ) {
	D = Direction_;
	SP = SP_;
}

//?§??????¨???????????????????????????????????????????????????
Vec::Vec( double x_ = 0.0L, double y_ = 0.0L, double z_ = 0.0L, Point SP_ = Point() ) {
	*this = Vec( D3( x_, y_, z_ ), SP_ );
}

Vec Vec::operator+( Vec Partner ) {
	return Vec( D.X + Partner.D.X, D.Y + Partner.D.Y, D.Z + Partner.D.Z, SP );
}

Vec Vec::operator*( Vec Partner ) {
	return Vec( D.X * Partner.D.X, D.Y * Partner.D.Y, D.Z * Partner.D.Z, SP );
}

Vec Vec::operator*( double ld ) {
	return Vec( D*ld, SP );
}

Vec Vec::operator-( Vec Partner ) {
	return *this + ( Partner*( -1.L ) );
}


Vec Vec::operator/( Vec Partner ) {
	return Vec( D.X / Partner.D.X, D.Y / Partner.D.Y, D.Z / Partner.D.Z, SP );
}

Vec Vec::operator/( double ld ) {
	return *this*( 1.L / ld );
}

bool Vec::operator== ( Vec Partner ) {
	return D == Partner.D&&SP == Partner.SP;
}

bool Vec::operator==( double ) {
	return ( *this ) == Vec();
}

//??????
Vec Vec::Cross_product( Vec Partner ) {
	return Vec( D.Y*Partner.getD().Z - D.Z*Partner.getD().Y, D.Z*Partner.getD().X - D.X*Partner.getD().Z, D.X*Partner.getD().Y - D.Y*Partner.getD().X );
}

//??????
double Vec::Inner_product( Vec Partner ) {
	return D.X*Partner.getD().X + D.Y*Partner.getD().Y + D.Z*Partner.getD().Z;
}

//???????????????????????????????????????
Vec::Vec( Point A, Point B ) {
	*this = Vec( B.getX() - A.getX(), B.getY() - A.getY(), B.getZ() - A.getZ(), A );
}

//?§?????????????
Point Vec::getSP() {
	return SP;
}

//???????????????
Point Vec::getGP() {
	return Point( SP.getX() + D.X, SP.getY() + D.Y, SP.getZ() + D.Z );
}

//???????????????
D3 Vec::getD() {
	return D;
}

//???????????????
double Vec::length() {
	return sqrtl( D.X*D.X + D.Y*D.Y + D.Z*D.Z );
}

//??????????????????(??????1)?????????
Vec Vec::Unit_vec() {
	return Vec( *this ) / ( *this ).length();
}

//????????????????????????(?§??????????????????????)
Vec Vec::Inverse_vec() {
	return ( *this )*-1.L;
}

//????????????????????????(?§??????¨???????????\????????????)
Vec Vec::Reverse_vec() {
	return Vec( ( *this ).Inverse_vec().getD(), ( *this ).getGP() );
}

//?????´????????????
bool Vec::Vertical( Vec Partner ) {
	return ( *this ).Inner_product( Partner ) == 0;
}

//??????????????????
bool Vec::Parallel( Vec Partner ) {
	return ( *this ).Unit_vec().getD() == Partner.Unit_vec().getD() || ( *this ).Unit_vec().Inverse_vec().getD() == Partner.Unit_vec().getD();
}

//??????????????????????????????????????????????????????
bool Vec::isIntersection( Vec Partner ) {
	int count = 0;
	Vec O = Partner.Cross_product( Vec( Partner.getSP(), ( *this ).getSP() ) );
	Vec P = Partner.Cross_product( Vec( Partner.getSP(), ( *this ).getGP() ) );
	Vec Q = ( *this ).Cross_product( Vec( ( *this ).getSP(), Partner.getSP() ) );
	Vec R = ( *this ).Cross_product( Vec( ( *this ).getSP(), Partner.getGP() ) );
	return ( !( *this ).Parallel( Partner ) ) && (
		O.getD().X*P.getD().X < D3().EPS&& O.getD().Y*P.getD().Y < D3().EPS&& O.getD().Z*P.getD().Z < D3().EPS ) && (
			Q.getD().X*R.getD().X < D3().EPS&& Q.getD().Y*R.getD().Y < D3().EPS&& Q.getD().Z*R.getD().Z < D3().EPS );
}

//????????????????£???????????????????
//?????????????????????????????????????¢???????????????¨???
//TODO:????¬?????????´???????????????
Point Vec::IntersectionPoint( Vec Partner ) {
	if( ( *this ).isIntersection( Partner ) ) {
		double d1 = abs( Partner.Cross_product( Vec( Partner.getSP(), ( *this ).getSP() ) ).D.Z );
		double d2 = abs( Partner.Cross_product( Vec( Partner.getSP(), ( *this ).getGP() ) ).D.Z );
		double t = d1 / ( d1 + d2 );
		return Vec( ( ( *this )*t ).getD(), ( *this ).getSP() ).getGP();
	} else {
		return Point();
	}
	return Point();
}

//????????????????????????????????????????????????????????????
bool Vec::onVecPoint( Point A ) {
	Vec Test( ( *this ).getSP(), A );
	if( A == ( ( *this ).getSP() ) || ( Test.Parallel( *this ) && ( *this ).getD().X / Test.getD().X >= 1.0L ) ) {
		return true;
	}
	return false;
}

//???????§????2????????????????????¢???????±???????
double Vec::S_vec( Vec B ) {
	if( ( ( *this ).getSP() == B.getSP() ) ) {
		Vec G = ( *this ).Cross_product( B );
		return sqrtl( G.Inner_product( G ) ) / 2.L;
	}
	if( ( *this ).getGP() == B.getSP() ) {
		return ( *this ).Reverse_vec().S_vec( B );
	}
	if( ( *this ).getSP() == B.getGP() ) {
		return ( *this ).S_vec( B.Reverse_vec() );
	}
	if( ( *this ).getGP() == B.getGP() ) {
		return ( *this ).Reverse_vec().S_vec( B.Reverse_vec() );
	}

	return -1.L;
}

//???????§???????????????????????????¨?§???????????????£??????????????????????????????
//?????????????????¨??????????????????????????????
//TODO ?§??????¨?????????????????????
double Vec::V_vec( Vec B, Vec C ) {
	Vec G = ( *this ).Cross_product( B );
	return G.Inner_product( C ) / 6.L;
	return 0;
}

ostream & operator<<( ostream & os, const Vec &v ) {
	if( DEBUG ) {
		os << "Vec" << endl;
		os << "start point" << endl;
		os << v.SP << endl;
		os << "vec" << endl;
		os << v.D << endl;
	}
	return os;
}



class Points {
private:
	vector<Point>VP;

public:
	void push( Point p ) {
		VP.push_back( p );
	}
	bool erase( Point p ) {
		auto now = find( VP.begin(), VP.end(), p );
		if( now != VP.end() ) {
			VP.erase( now );
			return 0;
		} else {
			return 1;
		}
	}

	void print() {
		for( auto x : VP ) {
			cout << x << endl;
		}
	}

	//sort????????????X?????§?°?->Y?????§?°?->Z?????§?°????
	void sort() {
		std::sort( VP.begin(), VP.end() );
	}

};

class PointDistance {
public:
	vector <int> findPoint( int x1, int y1, int x2, int y2 ) {
		Point A( x1, y1 ), B( x2, y2 );
		for( int i = -100; i <= 100; i++ ) {
			for( int j = -100; j <= 100; j++ ) {
				if( Vec( A, Point( i, j ) ).length() > Vec( B, Point( i, j ) ).length() && Vec( B, Point( i, j ) ).length() >= 1 ) {
					return vector<int>{i, j };
				}
			}
		}


	}
};



vector<vector<pair<long long int, double>>>makelist( vector<Point>&townlist, Vec DisallowVec ) {
	vector<vector<pair<long long int, double>>>ret( townlist.size() );
	for( size_t i = 0; i < townlist.size(); i++ ) {
		for( size_t j = i + 1; j < townlist.size(); j++ ) {
			Vec now = Vec( townlist[i], townlist[j] );
			if( !now.isIntersection( DisallowVec ) ) {
				ret[i].push_back( make_pair( j, now.length() ) );
				ret[j].push_back( make_pair( i, now.length() ) );
			}
		}
	}
	return ret;
}

double dijkstra( vector<vector<pair<long long int, double>>>  listLen ) {
	vector<double>ret( listLen.size(), DBL_MAX / 10 );
	priority_queue<pair< double, long long int>, vector<pair<double, long long int>>, greater<pair<double, long long int>>>que;
	que.push( make_pair( 0, 0 ) );
	ret[0] = 0;
	while( que.size() ) {
		auto now = que.top(); que.pop();
		if( now.second == 1 ) {
			break;
		}
		if( now.first != ret[now.second] ) {
			continue;
		}
		for( auto next : listLen[now.second] ) {
			if( ret[next.first] > now.first + next.second ) {
				ret[next.first] = now.first + next.second;
				if( ret[next.first] < ret[1] ) {
					que.push( make_pair( now.first + next.second, next.first ) );
				}
			}
		}
	}
	return ret[1];
}


int main() {
	long long int NA, NB;
	cin >> NA >> NB;
	vector<Point>townA( NA ), townB( NB );
	for( size_t i = 0; i < NA; i++ ) {
		double x, y;
		cin >> x >> y;
		townA[i] = Point( x, y );
	}
	for( size_t i = 0; i < NB; i++ ) {
		double x, y;
		cin >> x >> y;
		townB[i] = Point( x, y );
	}

	auto listA = makelist( townA, Vec( townB[0], townB[1] ) );
	auto listB = makelist( townB, Vec( townA[0], townA[1] ) );

	double lenA = dijkstra( listA );
	double lenB = dijkstra( listB );

	if( lenA == DBL_MAX / 10 && lenB == DBL_MAX / 10 ) {
		cout << -1 << endl;
	} else {
		cout << fixed << setprecision( 20 ) << min( lenA + Vec( townB[0], townB[1] ).length(), lenB + Vec( townA[0], townA[1] ).length() ) << endl;
	}
}

Measured memory_bytes: 50800