#include <bits/stdc++.h>
using namespace std;
using DBL = long double;
const DBL PI = acosl(DBL(-1));
const DBL INF = 1e20;
const DBL EPS = 1e-8;
inline DBL sqr(DBL x) { return x * x; }
inline int sgn(DBL x) { return (x > EPS) - (x < (-EPS)); }
inline int cmp(DBL x, DBL y) { return sgn((x - y) / max(DBL(1), fabsl(x))); }
struct point {
  DBL x, y;
  point() {}
  point(DBL x, DBL y) : x(x), y(y) {}
  void input() {
    int _x, _y;
    scanf("%d%d", &_x, &_y);
    x = _x, y = _y;
  }
  bool operator<(const point &p) const {
    if (fabsl(x - p.x) > EPS) return x < p.x;
    return y + EPS < p.y;
  }
  bool operator==(const point &p) const {
    return fabsl(x - p.x) < EPS && fabsl(y - p.y) < EPS;
  }
};
point operator+(point p1, point p2) { return point(p1.x + p2.x, p1.y + p2.y); }
point operator-(point p1, point p2) { return point(p1.x - p2.x, p1.y - p2.y); }
point operator*(point p, DBL c) { return point(p.x * c, p.y * c); }
point operator/(point p, DBL c) { return point(p.x / c, p.y / c); }
DBL dis(point p) { return sqrtl(sqr(p.x) + sqr(p.y)); }
DBL dis(point p1, point p2) { return dis(p1 - p2); }
DBL dis2(point p) { return sqr(p.x) + sqr(p.y); }
DBL dis2(point p1, point p2) { return dis2(p1 - p2); }
DBL vect(point p1, point p2) { return p1.x * p2.y - p2.x * p1.y; }
DBL vect(point p, point p1, point p2) { return vect(p1 - p, p2 - p); }
DBL scal(point p1, point p2) { return p1.x * p2.x + p1.y * p2.y; }
DBL scal(point p, point p1, point p2) { return scal(p1 - p, p2 - p); }
DBL getAngle(point p) { return atan2l(p.y, p.x); }
DBL getAngle(point p, point p1, point p2) {
  return acosl(scal(p, p1, p2) / dis(p - p1) / dis(p - p2));
}
point normalize(point p) { return p / dis(p); }
point virt(point p) { return point(-p.y, p.x); }
point rot(point p, DBL t) {
  return point(p.x * cos(t) - p.y * sin(t), p.x * sin(t) + p.y * cos(t));
}
point polar(point p, DBL r, DBL t) {
  return point(p.x + r * cos(t), p.y + r * sin(t));
}
point projection(point a, point b, point p) {
  return a + (a - b) * (scal(p - a, a - b) / dis2(a - b));
}
DBL disToLine(point p, point p1, point p2) {
  return fabsl(vect(p, p1, p2)) / dis(p1, p2);
}
DBL disToSeg(point p, point p1, point p2) {
  if (scal(p1, p, p2) < 0) return dis(p, p1);
  if (scal(p2, p, p1) < 0) return dis(p, p2);
  return disToLine(p, p1, p2);
}
bool onLine(point p, point p1, point p2) {
  return fabsl(vect(p1 - p, p2 - p)) < EPS;
}
bool onSeg(point p, point p1, point p2) {
  if (!onLine(p, p1, p2)) return 0;
  return (p1.x - p.x) * (p2.x - p.x) < EPS && (p1.y - p.y) * (p2.y - p.y) < EPS;
}
bool cross(point p1, point p2, point p3, point p4) {
  return vect(p1, p2, p3) * vect(p1, p2, p4) < -EPS &&
         vect(p3, p4, p1) * vect(p3, p4, p2) < -EPS;
}
bool common(point p1, point p2, point p3, point p4) {
  if (max(p1.x, p2.x) + EPS < min(p3.x, p4.x) ||
      max(p3.x, p4.x) + EPS < min(p1.x, p2.x))
    return 0;
  if (max(p1.y, p2.y) + EPS < min(p3.y, p4.y) ||
      max(p3.y, p4.y) + EPS < min(p1.y, p2.y))
    return 0;
  return vect(p1, p2, p3) * vect(p1, p2, p4) < EPS &&
         vect(p3, p4, p1) * vect(p3, p4, p2) < EPS;
}
int posLineLine(point p1, point p2, point p3, point p4, point &p) {
  DBL s1 = vect(p1, p2, p3), s2 = vect(p1, p2, p4);
  if (fabsl(s1 - s2) < EPS) {
    if (fabsl(s1) < EPS) return 2;
    return 0;
  }
  p = p3 + (p4 - p3) * (s1 / (s1 - s2));
  return 1;
}
int posCirLine(point p, DBL r, point p1, point p2, point *q) {
  DBL a = dis2(p1 - p2);
  DBL b = scal(p1, p, p2);
  DBL c = dis2(p - p1) - sqr(r);
  DBL d2 = sqr(b) - a * c;
  if (d2 < -EPS) return 0;
  DBL d = sqrtl(fabsl(d2));
  q[0] = p1 + (p2 - p1) * ((b + d) / a);
  q[1] = p1 + (p2 - p1) * ((b - d) / a);
  if (d2 < EPS) return 1;
  return 2;
}
int posCirCir(point p1, DBL r1, point p2, DBL r2, point *q) {
  if (p1 == p2) return 0;
  DBL dx = p2.x - p1.x, dy = p2.y - p1.y;
  DBL d = dis(p1 - p2);
  DBL e = (sqr(r1) - sqr(r2) + sqr(d)) / 2 / d;
  DBL f2 = sqr(r1) - sqr(e);
  if (f2 < -EPS) return 0;
  DBL f = sqrtl(fabsl(f2));
  q[0] = point(p1.x + (e * dx - f * dy) / d, p1.y + (e * dy + f * dx) / d);
  q[1] = point(p1.x + (e * dx + f * dy) / d, p1.y + (e * dy - f * dx) / d);
  if (f2 < EPS) return 1;
  return 2;
}
vector<point> convex_hull(vector<point> ps) {
  if ((int)ps.size() <= 1) return ps;
  int n = ps.size(), k = 0;
  sort(ps.begin(), ps.end());
  vector<point> ch(2 * n);
  for (int i = 0; i < n; ch[k++] = ps[i++])
    while (k >= 2 && vect(ch[k - 2], ch[k - 1], ps[i]) < EPS) --k;
  for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--])
    while (k >= t && vect(ch[k - 2], ch[k - 1], ps[i]) < EPS) --k;
  ch.resize(k - 1);
  return ch;
}
const int maxn = 1010;
struct segment {
  point A, B;
  segment() {}
  segment(point A, point B) : A(A), B(B) {}
  void input() {
    A.input();
    B.input();
  }
} seg[maxn];
DBL segToseg(segment A, segment B) {
  DBL v1 = min(disToSeg(A.A, B.A, B.B), disToSeg(A.B, B.A, B.B));
  DBL v2 = min(disToSeg(B.A, A.A, A.B), disToSeg(B.B, A.A, A.B));
  return min(v1, v2);
}
int n, a, b;
point st, en;
int q[maxn], qh, qt;
int vis[maxn];
int di[maxn];
int main() {
  scanf("%d%d", &a, &b);
  st.input();
  en.input();
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    seg[i].input();
    di[i] = 0x3f3f3f3f;
  }
  qh = qt = 0;
  DBL d = dis(st, en);
  DBL ans = 1e20;
  if (sgn(d - (DBL)a) <= 0) {
    printf("%.20Lf\n", d);
  } else {
    for (int i = 0; i < n; i++) {
      DBL d = disToSeg(st, seg[i].A, seg[i].B);
      if (sgn(d - (DBL)a) <= 0) {
        q[qt++] = i;
        di[i] = 1;
        vis[i] = 1;
      }
    }
    bool reach = false;
    while (qh < qt) {
      int f = q[qh++];
      for (int i = 0; i < n; i++) {
        if (vis[i]) continue;
        DBL d = segToseg(seg[f], seg[i]);
        if (sgn(d - (DBL)a) <= 0) {
          q[qt++] = i;
          di[i] = di[f] + 1;
          vis[i] = 1;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      if (!vis[i]) continue;
      DBL d = disToSeg(en, seg[i].A, seg[i].B);
      if (sgn(d - (DBL)a) <= 0) {
        reach = true;
        if (ans > (DBL)di[i] * (a + b) + d) ans = (DBL)di[i] * (a + b) + d;
      }
    }
    if (reach)
      printf("%.20Lf\n", ans);
    else
      puts("-1");
  }
}
