#include <bits/stdc++.h>
using namespace std;
bool debug = false;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
double dd(double x1, double y1, double x2, double y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
double a, b, ax, ay, bx, by;
struct trench {
  int x1, x2, y1, y2, ori, d = 2105;
  double t;
  void init() {
    t = 2105 * (a + b);
    if (x1 == x2) {
      ori = 0;
      if (y1 > y2) swap(y1, y2);
    } else {
      ori = 1;
      if (x1 > x2) swap(x1, x2);
    }
  }
  double dis(double x, double y) {
    double d = min(dd(x, y, x1, y1), dd(x, y, x2, y2));
    if (ori == 0) {
      if (y > y1 && y < y2) d = min(d, abs(x - x1));
    } else if (x > x1 && x < x2)
      d = min(d, abs(y - y1));
    if (d < a || abs(d - a) < 1e-20) return d;
    return 1 << 30;
  }
} tr[2105];
double dist(trench &p, trench &q) {
  return min(min(p.dis(q.x1, q.y1), p.dis(q.x2, q.y2)),
             min(q.dis(p.x1, p.y1), q.dis(p.x2, p.y2)));
}
bool ck(trench &from, trench &to) {
  double dd = dist(from, to);
  if (dd > a + 1e-20) return 0;
  to.t = min(to.t, from.d * (a + b) + dd);
  if (to.d > from.d + 1) {
    to.d = from.d + 1;
    return 1;
  } else {
    return 0;
  }
}
int main() {
  scanf("%lf%lf", &a, &b);
  cin >> ax >> ay >> bx >> by;
  scanf("%d", &n);
  for (int(i) = 0; (i) < (int)(n); (i)++) {
    scanf("%d%d%d%d", &tr[i].x1, &tr[i].y1, &tr[i].x2, &tr[i].y2);
    tr[i].init();
  }
  tr[n].x1 = tr[n].x2 = ax;
  tr[n].y1 = tr[n].y2 = ay;
  tr[n].init();
  n++;
  tr[n].x1 = tr[n].x2 = bx;
  tr[n].y1 = tr[n].y2 = by;
  tr[n].init();
  n++;
  tr[n - 2].d = 0;
  tr[n - 2].t = 0;
  priority_queue<pair<int, int> > q;
  q.push({-tr[n - 2].d, n - 2});
  while (!q.empty()) {
    int d = -q.top().first;
    int k = q.top().second;
    q.pop();
    if (d != tr[k].d) {
      continue;
    }
    for (int i = 0; i < n; ++i) {
      if (tr[i].d > d && ck(tr[k], tr[i])) {
        q.push({-tr[i].d, i});
      }
    }
  }
  if (tr[n - 1].d >= 2105)
    puts("-1");
  else
    printf("%.10lf\n", tr[n - 1].t);
  return 0;
}
