// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) begin(V), end(V)
#define ALLR(V) rbegin(V), rend(V)
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;

#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

const double eps = 1e-6;
const long double pi = 3.14159265358979323846264338327950288419716939937510L;

using Point = complex<double>;

struct DualPoints : public pair<Point, Point> {
    using pair<Point, Point>::pair;

    Point& operator [](size_t idx) { return idx == 0 ? first : second; }
    
    const Point& operator [](size_t idx) const { return idx == 0 ? first : second; }
};

struct get_xy {
    double &x, &y;

    get_xy(double &x, double &y) : x(x), y(y) { }

    get_xy& operator =(const Point &p) {
        x = real(p);
        y = imag(p);
        return *this;
    }
};

struct Line : public DualPoints {
    using DualPoints::DualPoints;
};

struct Seg : public DualPoints {
    using DualPoints::DualPoints;
};

double dot(const Point &a, const Point &b) {
    return (conj(a) * b).real();
}

double cross(const Point &a, const Point &b) {
    return (conj(a) * b).imag();
}

enum ccwd {
    Clock = -1,
    CoClock = 1,
    CAB = 2,
    ABC = -2,
    ACB = 0,
};

ccwd ccw(Point a, Point b, Point c) {
    b -= a;
    c -= a;
    double p, q;
    {
        auto tmp = conj(b) * c;
        p = tmp.real();
        q = tmp.imag();
    }
    if (0 < q) return CoClock;
    if (q < 0) return Clock;
    if (p < 0) return CAB;
    if (norm(b) < norm(c)) return ABC;
    return ACB;
}

bool is_zero(double a) {
    return abs(a) <= eps;
}

bool is_parallel(const Line &l1, const Line &l2) {
    return is_zero(cross(l1[1] - l1[0], l2[1] - l2[0]));
}

bool is_same_line(Point o, Point a, Point b) {
    return is_zero(cross(a - o, b - o));
}

bool intersect(const Line &p, const Line &q) {
    if (!is_parallel(p, q)) return true;
    return is_same_line(p[0], p[1], q[1]);
}

bool intersect(const Line &l, const Seg &s) {
    double a = cross(l[1] - l[0], s[0] - l[0]);
    double b = cross(l[1] - l[0], s[1] - l[0]);
    return a * b < 0;
}

bool intersect(const Seg &p, const Seg &q) {
    bool pf = (ccw(p[0], p[1], q[0]) * ccw(p[0], p[1], q[1])) <= 0;
    bool qf = (ccw(q[0], q[1], p[0]) * ccw(q[0], q[1], p[1])) <= 0;
    return pf && qf;
}

bool intersect(const Line &l, const Point &p) {
    return is_same_line(p, l[0], l[1]);
}

bool intersect(const Seg &s, const Point &p) {
    double l1 = abs(s[0] - s[1]);
    double l2 = abs(s[0] - p);
    double l3 = abs(s[1] - p);
    return is_zero(l2 + l3 - l1);
}

// projection from p to l
Point proj(const Line &l, const Point &p) {
    double mul = dot(p - l[0], l[1] - l[0]) / norm(l[0] - l[1]);  // cos(theta) / (p-l[0]).norm()
    return l[0] + mul * (l[1] - l[0]);
}

Point refl(const Line &l, const Point &p) {
    Point pr = proj(l, p);
    return p + (2. * (pr - p));
}

double distance(const Line &l, const Point &p) {
    return abs(p - proj(l, p));
}

double distance(const Line &p, const Line &q) {
    if (is_parallel(p, q)) return distance(p, q[0]);
    return 0;
}

double distance(const Line &l, const Seg &s) {
    if (intersect(l, s)) return 0;
    return min(distance(l, s[0]), distance(l, s[1]));
}

double distance(const Seg &s, const Point &p) {
    Line l(s[0], s[1]);
    Point pr = proj(l, p);
    if (intersect(s, pr)) return abs(pr - p);
    return min(abs(s[0] - p), abs(s[1] - p));
}

double distance(const Seg &p, const Seg &q) {
    if (intersect(p, q)) return 0;
    return var_min(distance(p, q[0]), distance(p, q[1]),
                   distance(q, p[0]), distance(q, p[1]));
}

double fix_arg(double arg) {
    arg += 2 * pi;
    if (2 * pi <= arg) arg -= 2 * pi;
    return arg;
}

bool comp_coclock(const Point &p1, const Point &p2) {
    return fix_arg(arg(p1)) < fix_arg(arg(p2));
}

Point rotate(const Point &p, double arg) {
    complex<double> r(cos(arg), sin(arg));
    return p * r;
}

const double inf = 5e15;
using DN = pair<double, int>;

double distance(const Point &a, const Point &b) {
    return sqrt(norm(a - b));
}

double solve(const V<Point> &va, const V<Point> &vb) {
    double ret = distance(va[0], va[1]);
    Seg line(va[0], va[1]);

    auto is_cross = [&](int i, int j) {
        Seg s(vb[i], vb[j]);
        return intersect(line, s);
    };

    V<double> dists(vb.size(), inf);
    dists[0] = 0;
    priority_queue<DN, V<DN>, greater<DN>> pq;
    pq.emplace(0, 0);
    while (pq.size()) {
        double d;
        int n;
        tie(d, n) = pq.top();
        pq.pop();
        if (dists[n] < d) continue;
        for (int nxt = 0; nxt < vb.size(); nxt++) {
            if (nxt == n) continue;
            if (is_cross(n, nxt)) continue;
            double c = distance(vb[n], vb[nxt]);
            double nd = d + c;
            if (dists[nxt] <= nd) continue;
            dists[nxt] = nd;
            pq.emplace(nd, nxt);
        }
    }

    if (dists[1] == inf) return inf;
    else return ret + dists[1];
}

void input(V<Point> &v) {
    for (auto &&e : v) {
        double x, y;
        cin >> x >> y;
        e = Point(x, y);
    }
}

int main() {
    ll na, nb;
    cin >> na >> nb;
    V<Point> va(na), vb(nb);
    input(va);
    input(vb);
    double ans = min(solve(va, vb), solve(vb, va));
    (ans == inf ? (cout << -1) : (cout << ans)) << endl;
    return 0;
}



Measured memory_bytes: 3472