#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define seg_size 262144LL
#define MOD 998244353LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

typedef complex<long double> Point;
typedef pair<complex<long double>, complex<long double>> Line;

long double dot(Point a, Point b) {
    return (a.real() * b.real() + a.imag() * b.imag());
}
long double cross(Point a, Point b) {
    return (a.real() * b.imag() - a.imag() * b.real());
}

long double Dist_Line_Point(Line a, Point b) {
    if (dot(a.second - a.first, b - a.first) < eps) return abs(b - a.first);
    if (dot(a.first - a.second, b - a.second) < eps) return abs(b - a.second);
    return abs(cross(a.second - a.first, b - a.first)) / abs(a.second - a.first);
}

int is_intersected_ls(Line a, Line b) {
    return (cross(a.second - a.first, b.first - a.first) * cross(a.second - a.first, b.second - a.first) < eps) &&
        (cross(b.second - b.first, a.first - b.first) * cross(b.second - b.first, a.second - b.first) < eps);
}

Point intersection_l(Line a, Line b) {
    Point da = a.second - a.first;
    Point db = b.second - b.first;
    return a.first + da * cross(db, b.first - a.first) / cross(db, da);
}

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}

unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

#define int ll

void solve(){
    int n[2];
    REP(i, 2) {
        cin >> n[i];
    }
    vector<Point> vertexs[2];
    REP(i, 2) {
        REP(q, n[i]) {
            long double a, b;
            cin >> a >> b;
            vertexs[i].push_back(Point{ a,b });
        }
    }
    long double ans = 1e18;
    REP(i, 2) {
        long double dist[2000] = {};
        REP(q, 2000) {
            dist[q] = 1e18;
        }
        dist[0] = abs(vertexs[0][1] - vertexs[0][0]);
        priority_queue<pair<long double, int>, vector<pair<long double, int>>, greater<pair<long double, int>>> next;
        next.push(mp(dist[0], 0));
        while (next.empty() == false) {
            pair<long double, int> now = next.top();
            next.pop();
            if (dist[now.second] != now.first) continue;
            for (int q = 0; q < vertexs[1].size(); ++q) {
                if (now.second == q) continue;
                if (is_intersected_ls(mp(vertexs[0][0], vertexs[0][1]), mp(vertexs[1][now.second], vertexs[1][q])) == 1) continue;
                long double tmp = now.first + abs(vertexs[1][now.second] - vertexs[1][q]);
                if (dist[q] > tmp) {
                    dist[q] = tmp;
                    next.push(mp(tmp, q));
                }
            }
        }
        ans = min(ans, dist[1]);
        swap(vertexs[0], vertexs[1]);
    }
    if (ans == 1e18) {
        ans = -1;
    }
    cout << ans << endl;
}

#undef int
int main() {
    init();
    solve();
}


Measured memory_bytes: 3556