#include <bits/stdc++.h>
using namespace std;
const int OO = 1e9;
const long long INF = 1e18;
const int irand(int lo, int hi) {
  return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo;
}
const long long lrand(long long lo, long long hi) {
  return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo;
}
template <typename T>
T getnum() {
  int sign = 1;
  T ret = 0;
  char c;
  do {
    c = getchar();
  } while (c == ' ' || c == '\n');
  if (c == '-')
    sign = -1;
  else
    ret = c - '0';
  while (1) {
    c = getchar();
    if (c < '0' || c > '9') break;
    ret = 10 * ret + c - '0';
  }
  return sign * ret;
}
inline void ini(int &x) { x = getnum<int>(); }
inline void scani(int &x) { scanf("%d", &x); }
const double EPS = 1E-9;
const double PI = acos(-1.0);
const double INFD = 1E9;
double between_d(double x, double l, double r) {
  return (min(l, r) <= x + EPS && x <= max(l, r) + EPS);
}
double same_d(double x, double y) { return between_d(x, y, y); }
double dabs(double x) {
  if (x < EPS) return -x;
  return x;
}
struct point {
  double x, y;
  point() { x = y = 0.0; }
  point(double _x, double _y) {
    x = _x;
    y = _y;
  }
  bool operator<(point other) {
    if (x < other.x + EPS) return true;
    if (x + EPS > other.x) return false;
    return y < other.y + EPS;
  }
  bool operator==(point other) {
    return same_d(x, other.x) && same_d(y, other.y);
  }
};
double e_dist(point P1, point P2) { return hypot(P1.x - P2.x, P1.y - P2.y); }
double m_dist(point P1, point P2) {
  return dabs(P1.x - P2.x) + dabs(P1.y - P2.y);
}
double pointBetween(point P, point L, point R) {
  return (e_dist(L, P) + e_dist(P, R) == e_dist(L, R));
}
struct vec {
  double x, y;
  vec() { x = y = 0.0; }
  vec(double _x, double _y) {
    x = _x;
    y = _y;
  }
  vec(point A) {
    x = A.x;
    y = A.y;
  }
  vec(point A, point B) {
    x = B.x - A.x;
    y = B.y - A.y;
  }
};
vec scale(vec v, double s) { return vec(v.x * s, v.y * s); }
vec flip(vec v) { return vec(-v.x, -v.y); }
double dot(vec u, vec v) { return (u.x * v.x + u.y * v.y); }
double cross(vec u, vec v) { return (u.x * v.y - u.y * v.x); }
double norm_sq(vec v) { return (v.x * v.x + v.y * v.y); }
point translate(point P, vec v) { return point(P.x + v.x, P.y + v.y); }
point rotate(point P, point O, double angle) {
  vec v(O);
  P = translate(P, flip(v));
  return translate(point(P.x * cos(angle) - P.y * sin(angle),
                         P.x * sin(angle) + P.y * cos(angle)),
                   v);
}
point mid(point P, point Q) { return point((P.x + Q.x) / 2, (P.y + Q.y) / 2); }
double angle(point A, point O, point B) {
  vec OA(O, A), OB(O, B);
  return acos(dot(OA, OB) / sqrt(norm_sq(OA) * norm_sq(OB)));
}
int orientation(point P, point Q, point R) {
  vec PQ(P, Q), PR(P, R);
  double c = cross(PQ, PR);
  if (c < EPS) return -1;
  if (c > EPS) return 1;
  return 0;
}
struct line {
  double a, b, c;
  line() { a = b = c = 0.0; }
  line(double _a, double _b, double _c) {
    a = _a;
    b = _b;
    c = _c;
  }
  line(point P1, point P2) {
    if (P2 < P1) {
      point T;
      T = P1;
      P1 = P2;
      P2 = T;
    }
    if (same_d(P1.x, P2.x))
      a = 1.0, b = 0.0, c = -P1.x;
    else
      a = -(P1.y - P2.y) / (P1.x - P2.x), b = 1.0, c = -(a * P1.x) - P1.y;
  }
  line(point P, double slope) {
    if (same_d(slope, INFD))
      a = 1.0, b = 0.0, c = -P.x;
    else
      a = -slope, b = 1.0, c = -(a * P.x) - P.y;
  }
  bool operator==(line other) {
    return same_d(a, other.a) && same_d(b, other.b) && same_d(c, other.c);
  }
  double slope() {
    if (same_d(b, 0.0)) return INFD;
    return -(a / b);
  }
};
bool paralel(line L1, line L2) {
  return same_d(L1.a, L2.a) && same_d(L1.b, L2.b);
}
bool intersection(line L1, line L2, point &P) {
  if (paralel(L1, L2)) return false;
  P.x = (L2.b * L1.c - L1.b * L2.c) / (L2.a * L1.b - L1.a * L2.b);
  if (same_d(L1.b, 0.0))
    P.y = -(L2.a * P.x + L2.c);
  else
    P.y = -(L1.a * P.x + L1.c);
  return true;
}
double pointToLine(point P, point A, point B, point &C) {
  vec AP(A, P), AB(A, B);
  double u = dot(AP, AB) / norm_sq(AB);
  C = translate(A, scale(AB, u));
  return e_dist(P, C);
}
double lineToLine(line L1, line L2) {
  if (!paralel(L1, L2)) return 0.0;
  return dabs(L2.c - L1.c) / sqrt(L1.a * L1.a + L1.b * L1.b);
}
struct segment {
  point P, Q;
  line L;
  segment() {
    point T1;
    P = Q = T1;
    line T2;
    L = T2;
  }
  segment(point _P, point _Q) {
    if (_Q < _P) {
      point T1 = _P;
      _P = _Q;
      _Q = T1;
    }
    P = _P;
    Q = _Q;
    line T2(_P, _Q);
    L = T2;
  }
  bool operator==(segment other) { return P == other.P && Q == other.Q; }
};
bool onSegment(point P, segment second) {
  if (orientation(second.P, second.Q, P) != 0) return false;
  return between_d(P.x, second.P.x, second.Q.x) &&
         between_d(P.y, second.P.y, second.Q.y);
}
bool s_intersection(segment S1, segment S2) {
  double o1 = orientation(S1.P, S1.Q, S2.P);
  double o2 = orientation(S1.P, S1.Q, S2.Q);
  double o3 = orientation(S2.P, S2.Q, S1.P);
  double o4 = orientation(S2.P, S2.Q, S1.Q);
  if (o1 != o2 && o3 != o4) return true;
  if (o1 == 0 && onSegment(S2.P, S1)) return true;
  if (o2 == 0 && onSegment(S2.Q, S1)) return true;
  if (o3 == 0 && onSegment(S1.P, S2)) return true;
  if (o4 == 0 && onSegment(S2.Q, S2)) return true;
  return false;
}
double pointToSegment(point P, point A, point B, point &C) {
  vec AP(A, P), AB(A, B);
  double u = dot(AP, AB) / norm_sq(AB);
  if (u < EPS) {
    C = A;
    return e_dist(P, A);
  }
  if (u + EPS > 1.0) {
    C = B;
    return e_dist(P, B);
  }
  return pointToLine(P, A, B, C);
}
double segmentToSegment(segment S1, segment S2) {
  if (s_intersection(S1, S2)) return 0.0;
  double ret = INFD;
  point dummy;
  ret = min(ret, pointToSegment(S1.P, S2.P, S2.Q, dummy));
  ret = min(ret, pointToSegment(S1.Q, S2.P, S2.Q, dummy));
  ret = min(ret, pointToSegment(S2.P, S1.P, S1.Q, dummy));
  ret = min(ret, pointToSegment(S2.Q, S1.P, S1.Q, dummy));
  return ret;
}
const int N = 1005;
int a, b;
int n;
point start, endd;
segment sg[N];
queue<int> q;
int dist[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> a >> b;
  cin >> start.x >> start.y >> endd.x >> endd.y;
  cin >> n;
  for (int i = 1; i <= n; i += 1) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    sg[i] = segment(point(a, b), point(c, d));
  }
  if (e_dist(start, endd) <= a) {
    cout << fixed << setprecision(12) << e_dist(start, endd) << endl;
    return 0;
  }
  double ans = OO;
  q.push(0);
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    if (now == 0) {
      for (int i = 1; i <= n; i += 1) {
        point tmp;
        if (pointToSegment(start, sg[i].P, sg[i].Q, tmp) <= a) {
          if (dist[i] > 0) continue;
          dist[i] = a + b;
          q.push(i);
        }
      }
    } else {
      point tmp;
      if (pointToSegment(endd, sg[now].P, sg[now].Q, tmp) <= a) {
        ans = min(ans,
                  dist[now] + pointToSegment(endd, sg[now].P, sg[now].Q, tmp));
      }
      for (int i = 1; i <= n; i += 1) {
        if (segmentToSegment(sg[now], sg[i]) <= a) {
          if (dist[i] > 0) continue;
          dist[i] = dist[now] + a + b;
          q.push(i);
        }
      }
    }
  }
  if (ans == OO)
    cout << "-1" << endl;
  else
    cout << fixed << setprecision(12) << ans << endl;
  return 0;
}
