#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int A, B, v[N], n;
double dist[N];
long long st[N];
struct rec {
  int x1, x2, y1, y2;
} t[N];
long long dis(rec a, rec b) {
  return (((max(0, max(a.x1, b.x1) - min(a.x2, b.x2))) *
           (max(0, max(a.x1, b.x1) - min(a.x2, b.x2)))) +
          ((max(0, max(a.y1, b.y1) - min(a.y2, b.y2))) *
           (max(0, max(a.y1, b.y1) - min(a.y2, b.y2)))));
}
void init() {
  scanf("%d%d", &A, &B);
  scanf("%d%d%d%d", &t[1].x1, &t[1].y1, &t[2].x1, &t[2].y1);
  t[1].x2 = t[1].x1, t[1].y2 = t[1].y1;
  t[2].x2 = t[2].x1, t[2].y2 = t[2].y1;
  scanf("%d", &n);
  for (int i = 3; i <= n + 2; i++) {
    scanf("%d%d%d%d", &t[i].x1, &t[i].y1, &t[i].x2, &t[i].y2);
    if (t[i].x1 > t[i].x2) swap(t[i].x1, t[i].x2);
    if (t[i].y1 > t[i].y2) swap(t[i].y1, t[i].y2);
  }
  n += 2;
}
void spfa() {
  queue<int> q;
  for (int i = 1; i <= n; i++) dist[i] = 1e18 * 1.0, st[i] = (long long)1e18;
  dist[1] = 0, st[1] = 0;
  v[1] = 1;
  q.push(1);
  while (q.size()) {
    int now = q.front();
    q.pop();
    v[now] = 0;
    for (int i = 1; i <= n; i++)
      if (dis(t[now], t[i]) <= A * A) {
        double c = sqrt(dis(t[now], t[i]) * 1.0) + st[now] * (A + B) * 1.0;
        if (dist[i] > c) {
          dist[i] = c;
          st[i] = st[now] + 1;
          if (!v[i]) v[i] = 1, q.push(i);
        }
      }
  }
}
int main() {
  init();
  spfa();
  if (dist[2] != 1e18)
    printf("%.9f\n", dist[2]);
  else
    puts("-1");
}
