#include <bits/stdc++.h>
using namespace std;
int distance(int x1, int y1, int x2, int y2) {
  int dx = x1 - x2, dy = y1 - y2;
  return dx * dx + dy * dy;
}
int minDist(int x, int y, int x1, int y1, int x2, int y2) {
  int d = min(distance(x, y, x1, y1), distance(x, y, x2, y2));
  int dy = min(abs(y1 - y), abs(y2 - y)), dx = min(abs(x1 - x), abs(x2 - x));
  if (x1 > x2) swap(x1, x2);
  if (x >= x1 && x <= x2) d = min(d, dy * dy);
  if (y1 > y2) swap(y1, y2);
  if (y >= y1 && y <= y2) d = min(d, dx * dx);
  return d;
}
int g[1002][1002];
int x1[1002];
int x2[1002];
int Y1[1002];
int y2[1002];
int used[1002];
int path[1002];
int main() {
  int a, b, n, ax, ay, bx, by;
  cin >> a >> b;
  cin >> ax >> ay >> bx >> by;
  cin >> n;
  for (int i = 0; i <= n + 1; i++)
    for (int j = 0; j <= n + 1; j++) g[i][j] = a * a + 1;
  g[0][n + 1] = g[n + 1][0] = distance(ax, ay, bx, by);
  for (int i = 1; i <= n; i++) {
    cin >> x1[i] >> Y1[i] >> x2[i] >> y2[i];
    g[0][i] = g[i][0] = minDist(ax, ay, x1[i], Y1[i], x2[i], y2[i]);
    g[i][n + 1] = g[n + 1][i] = minDist(bx, by, x1[i], Y1[i], x2[i], y2[i]);
    for (int j = 1; j < i; j++)
      g[i][j] = g[j][i] =
          min(min(minDist(x1[i], Y1[i], x1[j], Y1[j], x2[j], y2[j]),
                  minDist(x2[i], y2[i], x1[j], Y1[j], x2[j], y2[j])),
              min(minDist(x1[j], Y1[j], x1[i], Y1[i], x2[i], y2[i]),
                  minDist(x2[j], y2[j], x1[i], Y1[i], x2[i], y2[i])));
  }
  n++;
  queue<int> q;
  q.push(0);
  double res = 1000000000;
  memset(path, 1, sizeof(path));
  path[0] = 0;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    if (used[v]) continue;
    used[v] = 1;
    for (int i = 0; i <= n; i++)
      if (!used[i] && g[i][v] <= a * a && path[i] > path[v] + 1) {
        if (i == n)
          res = min(res, path[v] * (a + b) + sqrt((double)g[n][v]));
        else {
          q.push(i);
          path[i] = path[v] + 1;
          used[v] = 1;
        }
      }
  }
  if (res == 1000000000)
    cout << -1 << endl;
  else {
    printf("%.6Lf\n", res);
  }
  return 0;
}
