#include <bits/stdc++.h>
using namespace std;

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

typedef complex<long double> point;
typedef pair<point,point> line;
point polar(const long double &r, const long double &th) { return point(r*cosl(th),r*sinl(th)); }
bool equal(const long double x1,const long double x2){ return abs(x1-x2)<eps; }
bool equal(const point& a,const point& b){ return equal(a.real(),b.real()) and equal(a.imag(),b.imag()); }
long double length(const point& a){ return abs(a); }
long double distance(const point& a,const point& b){ return abs(a-b); }
long double dot(const point& a,const point& b){ return a.real()*b.real()+a.imag()*b.imag(); }
long double cross(const point& a,const point& b){ return a.real()*b.imag()-a.imag()*b.real(); }
int ccw(point a,point b,point 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 intersectSS(const line& s, const line& t){
    return ccw(s.first,s.second,t.first)*ccw(s.first,s.second,t.second) <= 0 &&
           ccw(t.first,t.second,s.first)*ccw(t.first,t.second,s.second) <= 0;
}

long double sub(int na,int nb,vector<point> &pa,vector<point> &pb){
    vector<long double> dist(nb,inf);
    vector<bool> done(nb);
    dist[0]=0;
    for(;;){
        int u=-1;
        rep(v,0,nb){
            if(!done[v] and (u==-1 or dist[u]>dist[v])) u=v;
        }
        if(u==-1) break;
        done[u]=true;
        rep(v,0,nb){
            if(intersectSS(line(pa[0],pa[1]),line(pb[u],pb[v]))) continue;
            long double d=dist[u]+abs(pb[u]-pb[v]);
            if(d<dist[v]) dist[v]=d;
        }
    }
    return abs(pa[0]-pa[1])+dist[1];
}

void solve(){
    int na,nb;
    cin >> na >> nb;
    vector<point> pa,pb;
    rep(i,0,na){
        long double x,y;
        cin >> x >> y;
        pa.push_back(point(x,y));
    }
    rep(i,0,nb){
        long double x,y;
        cin >> x >> y;
        pb.push_back(point(x,y));
    }
    long double ans=min(sub(na,nb,pa,pb),sub(nb,na,pb,pa));
    if(ans<inf) cout << ans << endl;
    else cout << -1 << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}