#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

int ccw(P a, P b, P 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 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;
}

typedef double Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

// ¹öª¢çÈ¢ê
Weight dijkstra2(const Graph &g, int s, int t) {
  vector<Weight> dist(g.size(), INF);
  dist[s] = 0;
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (dist[e.dst] < e.weight) continue;
    if (e.dst == t) return e.weight;
    FOR(f,g[e.dst]) {
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
  return 1e18;
}

P A[1000];
P B[1000];

int main() {
  int n,m;
  cin >> n >> m;
  REP(i, n) {
    int x,y;
    cin >> x >> y;
    A[i] = P(x,y);
  }
  REP(i, m) {
    int x,y;
    cin >> x >> y;
    B[i] = P(x,y);
  }
  double ans = 1e18;
  if (!intersectSS(L(A[0], A[1]), L(B[0], B[1]))) {
    ans = abs(A[0]-A[1]) + abs(B[0]-B[1]);
  } else {
    Graph g(n);
    REP(i, n) {
      REP(j, i) {
        if (!intersectSS(L(A[i], A[j]), L(B[0], B[1]))) {
          double dis = abs(A[i]-A[j]);
          g[i].push_back(Edge(i, j, dis));
          g[j].push_back(Edge(j, i, dis));
        }
      }
    }
    ans = min(ans, dijkstra2(g, 0, 1) + abs(B[0]-B[1]));
    g.assign(m, Edges());
    REP(i, m) {
      REP(j, i) {
        if (!intersectSS(L(A[0], A[1]), L(B[i], B[j]))) {
          double dis = abs(B[i]-B[j]);
          g[i].push_back(Edge(i, j, dis));
          g[j].push_back(Edge(j, i, dis));
        }
      }
    }
    ans = min(ans, dijkstra2(g, 0, 1) + abs(A[0]-A[1]));
  }
  if (ans > 1e17) {
    cout << -1 << endl;
  } else {
    printf("%.12f\n", ans);
  }
}

Measured memory_bytes: 17000