#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:25600000")
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-9;
bool d1[102400];
bool d2[102400];
long long sqr(long long x) { return x * x; }
struct segm {
  pair<long long, long long> A, B;
  double dist(pair<long long, long long> p) {
    pair<long long, long long> a = A;
    pair<long long, long long> b = B;
    if (a.first == b.first) {
      swap(a.first, a.second);
      swap(b.first, b.second);
      swap(p.first, p.second);
    }
    if (a.first > b.first) swap(a, b);
    if (a.first <= p.first && p.first <= b.first)
      return fabs(1.0 * (a.second - p.second));
    double d1 = sqrt(double(sqr(p.first - a.first) + sqr(p.second - a.second)));
    double d2 = sqrt(double(sqr(p.first - b.first) + sqr(p.second - b.second)));
    return min(d1, d2);
  }
  double dist(segm other) {
    double d1 = dist(other.A);
    double d2 = dist(other.B);
    return min(d1, d2);
  }
};
vector<segm> sg;
double a, b;
pair<long long, long long> start, fin;
int n;
double D[1024][1024];
double mn[1024];
bool active[1024];
int main() {
  cin >> a >> b;
  cin >> start.first >> start.second >> fin.first >> fin.second;
  cin >> n;
  sg.resize(n);
  for (long long i = 0; i < n; i++) {
    cin >> sg[i].A.first >> sg[i].A.second >> sg[i].B.first >> sg[i].B.second;
  }
  int vertices = n + 2;
  for (long long i = 0; i < vertices; i++)
    for (long long j = 0; j < vertices; j++) {
      if (j < i) {
        D[i][j] = D[j][i];
        continue;
      }
      if (i == j) {
        D[i][j] = 0;
        continue;
      }
      if (i == 0) {
        if (j + 1 < vertices)
          D[i][j] = sg[j - 1].dist(start);
        else
          D[i][j] = sqrt(double(sqr(start.first - fin.first) +
                                sqr(start.second - fin.second)));
        continue;
      }
      if (j + 1 < vertices)
        D[i][j] = min(sg[i - 1].dist(sg[j - 1]), sg[j - 1].dist(sg[i - 1]));
      else
        D[i][j] = sg[i - 1].dist(fin);
    }
  const double INF = 10000000000.0;
  memset(active, 0, sizeof active);
  for (long long i = 0; i < vertices; i++) mn[i] = INF;
  mn[0] = 0;
  active[0] = true;
  n = vertices;
  while (true) {
    int index = -1;
    for (long long i = 0; i < n; i++)
      if (active[i])
        if (index == -1 || mn[index] > mn[i]) index = i;
    if (index == -1) break;
    for (long long i = 0; i < n; i++)
      if (mn[i] > mn[index]) {
        double togo = D[i][index];
        if (togo > a) continue;
        double t = mn[index] + togo;
        if (i + 1 < vertices) t += b + (a - togo);
        if (t > mn[i]) continue;
        mn[i] = t;
        active[i] = true;
      }
    active[index] = false;
  }
  if (mn[n - 1] == INF)
    cout << "-1\n";
  else
    printf("%.12lf\n", mn[n - 1]);
}
