#include <bits/stdc++.h>
using namespace std;
struct point {
  double x, y;
  void read() { scanf("%lf%lf", &x, &y); }
};
double eps = 1e-8;
double a, b;
point s, t;
point p[1111], q[1111];
double dist[1111][1111], d[1111];
int n;
double sqr(double x) { return x * x; }
double calc(point x, point y, point z) {
  if (x.x == y.x) {
    if (min(x.y, y.y) <= z.y && z.y <= max(x.y, y.y)) return fabs(z.x - x.x);
    return sqrt(sqr(min(fabs(x.y - z.y), fabs(y.y - z.y))) +
                sqr(fabs(z.x - x.x)));
  } else {
    if (min(x.x, y.x) <= z.x && z.x <= max(x.x, y.x)) return fabs(z.y - x.y);
    return sqrt(sqr(min(fabs(x.x - z.x), fabs(y.x - z.x))) +
                sqr(fabs(z.y - x.y)));
  }
}
double calc(int x, int y) {
  double res = 1e18;
  res = min(res, calc(p[x], q[x], p[y]));
  res = min(res, calc(p[x], q[x], q[y]));
  res = min(res, calc(p[y], q[y], p[x]));
  res = min(res, calc(p[y], q[y], q[x]));
  if (res > a + eps) return 1e18;
  if (x == n || y == n) return res;
  return a;
}
int main() {
  scanf("%lf%lf", &a, &b);
  s.read();
  t.read();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    p[i].read();
    q[i].read();
  }
  n++;
  p[n] = q[n] = s;
  n++;
  p[n] = q[n] = t;
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) dist[i][j] = dist[j][i] = calc(i, j);
  for (int i = 1; i <= n; i++) dist[i][i] = 0;
  for (int i = 1; i <= n; i++) d[i] = 1e18;
  queue<int> q;
  q.push(n - 1);
  d[n - 1] = 0;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 1; i <= n; i++) {
      double cur = d[v] + dist[v][i];
      if (i != n) cur += b;
      if (d[i] > cur) {
        d[i] = cur;
        q.push(i);
      }
    }
  }
  if (d[n] > 1e9)
    puts("-1");
  else
    printf("%.10lf\n", d[n]);
  return 0;
}
