#include <bits/stdc++.h>
using namespace std;
const int MAX = 3e5 + 10;
const long long MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const long double EPS = 1e-7;
const long double PI = acos(-1);
bool eq(long double a, long double b) { return abs(a - b) <= EPS; }
struct point {
  long double x, y;
  int id;
  point(long double x = 0, long double y = 0) : x(x), y(y) {}
  point operator+(const point &o) const { return {x + o.x, y + o.y}; }
  point operator-(const point &o) const { return {x - o.x, y - o.y}; }
  point operator*(long double t) const { return {x * t, y * t}; }
  point operator/(long double t) const { return {x / t, y / t}; }
  long double operator*(const point &o) const { return x * o.x + y * o.y; }
  long double operator^(const point &o) const { return x * o.y - y * o.x; }
  bool operator<(const point &o) const {
    if (!eq(x, o.x)) return x < o.x;
    return y < o.y;
  }
  bool operator==(const point &o) const { return eq(x, o.x) and eq(y, o.y); }
};
long double norm(point a) { return sqrt(a * a); }
struct line {
  point p1, p2;
  long double a, b, c;
  line(point p1 = 0, point p2 = 0) : p1(p1), p2(p2) {
    a = p1.y - p2.y;
    b = p2.x - p1.x;
    c = -(a * p1.x + b * p1.y);
  }
  long double eval(point p) { return a * p.x + b * p.y + c; }
  bool inside(point p) { return eq(eval(p), 0); }
  point normal() { return point(a, b); }
  bool inside_seg(point p) {
    return (inside(p) and min(p1.x, p2.x) <= p.x and p.x <= max(p1.x, p2.x) and
            min(p1.y, p2.y) <= p.y and p.y <= max(p1.y, p2.y));
  }
};
long double dseg(point p, point a, point b) {
  if (((p - a) * (b - a)) < EPS) return norm(p - a);
  if (((p - b) * (a - b)) < EPS) return norm(p - b);
  return abs((p - a) ^ (b - a)) / norm(b - a);
}
vector<vector<pair<long double, long double>>> g(
    MAX + 1, vector<pair<long double, long double>>());
vector<long double> d(MAX + 1, LLINF);
priority_queue<pair<long double, long double>,
               vector<pair<long double, long double>>,
               greater<pair<long double, long double>>>
    fila;
void dijkstra(int k) {
  d[k] = 0;
  fila.push({0, k});
  while (!fila.empty()) {
    long double w = fila.top().first, u = fila.top().second;
    fila.pop();
    if (w > d[u]) continue;
    for (auto [v, w] : g[u]) {
      if (d[v] > d[u] + w) {
        d[v] = d[u] + w;
        fila.push({d[v], v});
      }
    }
  }
}
long double pDist(point p, pair<point, point> t) {
  return dseg(p, t.first, t.second);
}
long double trenchDist(pair<point, point> A, pair<point, point> B) {
  long double ans = LLINF;
  ans = min(ans, pDist(A.first, B));
  ans = min(ans, pDist(A.second, B));
  ans = min(ans, pDist(B.first, A));
  ans = min(ans, pDist(B.second, A));
  return ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cout << fixed << setprecision(6);
  int a, b, Ax, Ay, Bx, By;
  cin >> a >> b;
  cin >> Ax >> Ay >> Bx >> By;
  int n, x1, y1, x2, y2;
  cin >> n;
  vector<pair<point, point>> vt(n);
  for (int i = 0; i < n; i++) {
    cin >> x1 >> y1 >> x2 >> y2;
    vt[i].first = point(x1, y1);
    vt[i].second = point(x2, y2);
  }
  point pA = point(Ax, Ay);
  point pB = point(Bx, By);
  if (norm(pA - pB) <= a) {
    cout << norm(pA - pB) << '\n';
    return 0;
  }
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) {
      long double dist = trenchDist(vt[i], vt[j]);
      if (dist <= a + EPS) {
        g[i].push_back({j, a + b});
        g[j].push_back({i, a + b});
      }
    }
  for (int i = 0; i < n; i++) {
    long double dist = pDist(pA, vt[i]);
    if (dist <= a + EPS) g[n].push_back({i, a + b});
  }
  for (int i = 0; i < n; i++) {
    long double dist = pDist(pB, vt[i]);
    if (dist <= a + EPS) g[i].push_back({n + 1, dist});
  }
  dijkstra(n);
  if (d[n + 1] == LLINF)
    cout << -1 << '\n';
  else
    cout << d[n + 1] << '\n';
  return 0;
}
