#include <iostream>
#include <complex>
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
typedef complex<double> P;
typedef pair<P,P> L;
#define X real()
#define Y imag()
const double EPS = (1e-10);
const double INF = (1e15);

double dot(P a, P b){
  return a.X * b.X + a.Y * b.Y;
}
double cross(P a, P b){
  return a.X * b.Y - a.Y * b.X;
}

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if( cross(b,c) > EPS ) return +1;
  if( cross(b,c) < -EPS ) return -1;
  if( dot(b,c) < 0 ) return +2;
  if( abs(b) + EPS < abs(c) ) return -2;
  return 0;
}

bool is_cross(L a, L b){
  return (ccw(a.first,a.second,b.first)*ccw(a.first,a.second,b.second) <= 0 &&
          ccw(b.first,b.second,a.first)*ccw(b.first,b.second,a.second) <= 0);
}

double dijkstra(vector< vector< pair<int, double> > > &G){
  int N = G.size();
  priority_queue< pair<double, int> > wait;
  vector<double> D(N, INF);
  wait.emplace(0, 0);
  while(!wait.empty()){
    double d = -wait.top().first;
    int v = wait.top().second;
    wait.pop();
    if(d > D[v] + EPS) continue;
    D[v] = d;
    for(int i = 0; i < G[v].size(); ++i){
      int v_ = G[v][i].first;
      double d_ = d + G[v][i].second;
      if(d_ < D[v_]){
        D[v_] = d_;
        wait.emplace(-d_, v_);
      }
    }
  }
  return D[1];
}

double solve(vector<P> &A, vector<P> &B){
  L l = L(A[0], A[1]);
  int Nb = B.size();
  vector< vector< pair<int, double> > > G(Nb);
  for(int i = 0; i < Nb; ++i){
    for(int j = 0; j < i; ++j){
      if(is_cross(l, L(B[i], B[j]))) continue;
      G[i].emplace_back(j, abs(B[i] - B[j]));
      G[j].emplace_back(i, abs(B[i] - B[j]));
    }
  }
  return dijkstra(G) + abs(A[0] - A[1]);
}

int main(){
  int Na, Nb;
  cin >> Na >> Nb;
  vector<P> A(Na), B(Nb);
  for(int i = 0; i < Na; ++i){
    double x, y;
    cin >> x >> y;
    A[i] = P(x, y);
  }
  for(int i = 0; i < Nb; ++i){
    double x, y;
    cin >> x >> y;
    B[i] = P(x, y);
  }
  double ans = min(solve(A, B), solve(B, A));
  if(ans >= INF - EPS) cout << -1 << endl;
  else printf("%.12f\n", ans);
  return 0;
}

