#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
int a, b, n;
pair<int, int> A, B;
map<pair<int, int>, int> P2N;
map<int, vector<int> > P;
vector<vector<pair<int, int> > > N2P;
vector<set<pair<double, int> > > G;
double dist(int node) {
  if (N2P[node].size() == 2) {
    if (N2P[node][0].first == N2P[node][1].first) {
      if ((N2P[node][0].second <= B.second &&
           B.second <= N2P[node][1].second) ||
          (N2P[node][1].second <= B.second && B.second <= N2P[node][0].second))
        return abs(N2P[node][0].first - B.first);
    }
    if (N2P[node][0].second == N2P[node][1].second) {
      if ((N2P[node][0].first <= B.first && B.first <= N2P[node][1].first) ||
          (N2P[node][1].first <= B.first && B.first <= N2P[node][0].first))
        return abs(N2P[node][0].second - B.second);
    }
  }
  double result = 100000.0;
  for (auto Y : N2P[node]) {
    result = min(result,
                 sqrt(pow(B.first - Y.first, 2) + pow(B.second - Y.second, 2)));
  }
  return result;
}
void link(pair<int, int> X, pair<int, int> Y) {
  int node1 = P2N[X];
  int node2 = P2N[Y];
  if (node1 != node2) {
    if (node1 == n + 1) {
      G[node2].insert(make_pair(dist(node2), node1));
    } else if (node2 == n + 1) {
      G[node1].insert(make_pair(dist(node1), node2));
    } else {
      G[node1].insert(make_pair(a + b, node2));
      G[node2].insert(make_pair(a + b, node1));
    }
  }
}
void link(pair<int, int> X, int p, int marge) {
  for (auto it = lower_bound(P[p].begin(), P[p].end(), X.second - marge);
       it != P[p].end() && abs(*it - X.second) <= marge; ++it) {
    link(X, make_pair(p, *it));
  }
}
void linkv(pair<int, int> X, int x, int y2) {
  for (auto it = lower_bound(P[x].begin(), P[x].end(), X.second);
       it != P[x].end() && *it <= y2; ++it) {
    link(X, make_pair(x, *it));
  }
}
int main() {
  ios::sync_with_stdio(false);
  cout.precision(20);
  cin >> a >> b;
  cin >> A.first >> A.second >> B.first >> B.second;
  cin >> n;
  N2P.resize(n + 2);
  G.resize(n + 2);
  N2P[0].push_back(A);
  N2P[n + 1].push_back(B);
  P2N[A] = 0;
  P2N[B] = n + 1;
  P[A.first].push_back(A.second);
  P[B.first].push_back(B.second);
  for (int i = 0; i < n; i++) {
    pair<int, int> X, Y;
    cin >> X.first >> X.second >> Y.first >> Y.second;
    N2P[i + 1].push_back(X);
    N2P[i + 1].push_back(Y);
    P2N[X] = i + 1;
    P2N[Y] = i + 1;
    P[X.first].push_back(X.second);
    P[Y.first].push_back(Y.second);
  }
  vector<int> previous;
  for (auto it = P.begin(); it != P.end(); ++it) {
    sort(it->second.begin(), it->second.end());
    for (int i = 1; i < it->second.size(); ++i) {
      for (int j = i - 1; j >= 0 && it->second[i] - it->second[j] <= a; --j) {
        link(make_pair(it->first, it->second[i]),
             make_pair(it->first, it->second[j]));
      }
    }
    for (int i = 0; i < it->second.size(); ++i) {
      int x0 = it->first;
      for (int j = 0; j < N2P[P2N[make_pair(it->first, it->second[i])]].size();
           ++j) {
        x0 = min(x0, N2P[P2N[make_pair(it->first, it->second[i])]][j].first);
      }
      auto it2 = previous.rbegin();
      for (; it2 != previous.rend() && *it2 >= x0; it2++) {
        link(make_pair(it->first, it->second[i]), *it2, a);
      }
      for (; it2 != previous.rend() && x0 - *it2 <= a; it2++) {
        link(make_pair(it->first, it->second[i]), *it2,
             sqrt(a * a - pow(x0 - *it2, 2)));
      }
    }
    previous.push_back(it->first);
  }
  for (int k = 0; k < previous.size(); k++) {
    int x = previous[k];
    vector<int>& L = P[x];
    for (int i = 0; i < L.size(); ++i) {
      pair<int, int> X = make_pair(x, L[i]);
      int node = P2N[X];
      int y2 = max(N2P[node][0].second, N2P[node][1].second);
      if (N2P[node].size() == 2 && N2P[node][0].first == N2P[node][1].first &&
          L[i] != max(N2P[node][0].second, N2P[node][1].second)) {
        int y2 = max(N2P[node][0].second, N2P[node][1].second);
        for (int j = k - 1; j >= 0 && x - previous[j] <= a; j--) {
          linkv(X, previous[j], y2);
        }
        for (int j = k + 1; j < previous.size() && previous[j] - x <= a; j++) {
          linkv(X, previous[j], y2);
        }
      }
    }
  }
  vector<double> L(n + 2, -1);
  set<pair<double, int> > S;
  L[0] = 0;
  for (auto s : G[0]) {
    S.insert(s);
  }
  while (!S.empty()) {
    int node = S.begin()->second;
    double cost = S.begin()->first;
    S.erase(S.begin());
    if (L[node] == -1 || L[node] > cost) {
      L[node] = cost;
      for (auto s : G[node]) {
        S.insert(make_pair(s.first + cost, s.second));
      }
    }
  }
  cout << L[n + 1] << endl;
  return 0;
}
