#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)

using namespace std;

typedef pair<int,double>P;
typedef complex<double> C;

namespace std {
    bool operator < (const C& a, const C& b) {
        return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
    }
}

struct edge{
    int to;
    double cost;
};

const int MAX_N = 1002;

int na,nb;
double d[MAX_N];
int X1[MAX_N],Y1[MAX_N],X2[MAX_N],Y2[MAX_N];
vector<edge> G[MAX_N];

double cross(const C& a, const C& b) {
  return imag(conj(a)*b);
}
double dot(const C& a, const C& b) {
  return real(conj(a)*b);
}

struct L : public vector<C> {
  L(const C &a, const C &b) {
    push_back(a); push_back(b);
  }
};

int ccw(C a, C b, C c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

bool intersectLL(const L &l, const L &m) {
  return abs(cross(l[1]-l[0], m[1]-m[0])) > EPS || // non-parallel
         abs(cross(l[1]-l[0], m[0]-l[0])) < EPS;   // same line
}
bool intersectLS(const L &l, const L &s) {
  return cross(l[1]-l[0], s[0]-l[0])*       // s[0] is left of l
         cross(l[1]-l[0], s[1]-l[0]) < EPS; // s[1] is right of l
}
bool intersectLP(const L &l, const C &p) {
  return abs(cross(l[1]-p, l[0]-p)) < EPS;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

void dijkstra(int s)
{
	priority_queue<P,vector<P>,greater<P> > que;
	d[s] = 0;
	que.push(P(0,s));
	while(!que.empty()){
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		vector<edge>::iterator it = G[v].begin();
		rep(i,G[v].size()){
			if(d[G[v][i].to] > d[v] + G[v][i].cost){
				d[G[v][i].to] = d[v] + G[v][i].cost;
				que.push(P(d[G[v][i].to],G[v][i].to));
			}
		}
	}
}

int main()
{
	scanf("%d%d",&na,&nb);
	rep(i,na){
		scanf("%d%d",&X1[i],&Y1[i]);
	}
    rep(i,nb){
        scanf("%d%d",&X2[i],&Y2[i]);
    }
    rep(i,nb){
        d[i] = INF;
    }
    L l(C(X1[0],Y1[0]),C(X1[1],Y1[1]));
    rep(i,nb){
        for(int j=i+1;j<nb;j++){
            L l1(C(X2[i],Y2[i]),C(X2[j],Y2[j]));
            if(!intersectSS(l,l1)){
                G[i].push_back((edge){j,abs(l1[1]-l1[0])});
                G[j].push_back((edge){i,abs(l1[1]-l1[0])});
            }
        }
    }
    dijkstra(0);
    double cand1 = d[1] + abs(l[1]-l[0]);
    rep(i,na){
        G[i].clear();
        d[i] = INF;
    }
    L l2(C(X2[0],Y2[0]),C(X2[1],Y2[1]));
    rep(i,na){
        for(int j=i+1;j<na;j++){
            L l1(C(X1[i],Y1[i]),C(X1[j],Y1[j]));
            if(!intersectSS(l2,l1)){
                G[i].push_back((edge){j,abs(l1[1]-l1[0])});
                G[j].push_back((edge){i,abs(l1[1]-l1[0])});
            }
        }
    }
    dijkstra(0);
    double cand2 = d[1] + abs(l2[1]-l2[0]);
    if(min(cand1,cand2) >= INF){
        printf("-1\n");
    }else{
        printf("%.12f\n",min(cand1,cand2));
    }
	return 0;
}

Measured memory_bytes: 20712