#include <bits/stdc++.h>
struct point {
  int x, y;
};
enum segtype { vert, horiz };
struct segment {
  struct point p1, p2;
  double a, b, c, l;
  enum segtype type;
};
std::vector<std::vector<double> > g(1002, std::vector<double>(1002, 0));
double dest_points(struct point* p1, struct point* p2) {
  return sqrt((p1->x - p2->x) * (p1->x - p2->x) +
              (p1->y - p2->y) * (p1->y - p2->y));
}
double dest_pointseg(struct point* p, struct segment* s) {
  struct point closer;
  if (s->type == horiz) {
    if (s->p1.x <= p->x && p->x <= s->p2.x) {
      return abs(p->y - s->p1.y);
    } else {
      closer.x = (s->p2.x < p->x) ? s->p2.x : s->p1.x;
      closer.y = s->p1.y;
      return dest_points(&closer, p);
    }
  } else {
    if (s->p1.y <= p->y && p->y <= s->p2.y) {
      return abs(p->x - s->p1.x);
    } else {
      closer.y = (s->p2.y < p->y) ? s->p2.y : s->p1.y;
      closer.x = s->p1.x;
      return dest_points(&closer, p);
    }
  }
}
double dest_segseg(struct segment* s1, struct segment* s2) {
  struct segment* ps1 = s1;
  struct segment* ps2 = s2;
  struct segment* t;
  if (ps1->type != ps2->type) {
    if (ps1->type == horiz) {
      t = ps2;
      ps2 = ps1;
      ps1 = t;
    }
    if (ps1->p1.y <= ps2->p1.y && ps2->p1.y <= ps1->p2.y) {
      return std::min(abs(ps1->p1.x - ps2->p2.x), abs(ps1->p1.x - ps2->p1.x));
    } else if (ps2->p1.x <= ps1->p1.x && ps1->p1.x <= ps2->p2.x) {
      return std::min(abs(ps2->p1.y - ps1->p2.y), abs(ps2->p1.y - ps1->p1.y));
    } else {
      struct point p1, p2;
      if (ps1->p2.y < ps2->p1.y)
        p1 = ps1->p2;
      else
        p1 = ps1->p1;
      if (ps1->p2.x < ps2->p1.x)
        p2 = ps2->p1;
      else
        p2 = ps2->p2;
      return dest_points(&p1, &p2);
    }
  } else {
    if (ps1->type == horiz) {
      if (ps1->p1.x <= ps2->p1.x && ps2->p1.x <= ps1->p2.x ||
          ps1->p1.x <= ps2->p2.x && ps2->p2.x <= ps1->p2.x ||
          ps2->p1.x <= ps1->p1.x && ps1->p1.x <= ps2->p2.x ||
          ps2->p1.x <= ps1->p2.x && ps1->p2.x <= ps2->p2.x)
        return abs(ps1->p1.y - ps2->p1.y);
      else {
        struct point p1, p2;
        if (ps1->p1.x > ps2->p2.x) {
          p1 = ps2->p2;
          p2 = ps1->p1;
        } else {
          p1 = ps2->p1;
          p2 = ps1->p2;
        }
        return dest_points(&p1, &p2);
      }
    } else {
      if (ps1->p1.y <= ps2->p1.y && ps2->p1.y <= ps1->p2.y ||
          ps1->p1.y <= ps2->p2.y && ps2->p2.y <= ps1->p2.y ||
          ps2->p1.y <= ps1->p1.y && ps1->p1.y <= ps2->p2.y ||
          ps2->p1.y <= ps1->p2.y && ps1->p2.y <= ps2->p2.y)
        return abs(ps1->p1.x - ps2->p1.x);
      else {
        struct point p1, p2;
        if (ps1->p1.y > ps2->p2.y) {
          p1 = ps2->p2;
          p2 = ps1->p1;
        } else {
          p1 = ps2->p1;
          p2 = ps1->p2;
        }
        return dest_points(&p1, &p2);
      }
    }
  }
}
void fillsegment(struct segment* s) {
  s->type = (s->p1.x == s->p2.x) ? vert : horiz;
  if (s->p1.x > s->p2.x) std::swap(s->p1.x, s->p2.x);
  if (s->p1.y > s->p2.y) std::swap(s->p1.y, s->p2.y);
}
int main(int argc, char** argv) {
  int a, b;
  struct point pa, pb;
  scanf("%d %d", &a, &b);
  scanf("%d %d", &pa.x, &pa.y);
  scanf("%d %d", &pb.x, &pb.y);
  int n;
  scanf("%d", &n);
  int i, j;
  std::vector<struct segment> s(1000);
  struct segment seg;
  for (i = 0; i < n; i++) {
    scanf("%d %d %d %d", &seg.p1.x, &seg.p1.y, &seg.p2.x, &seg.p2.y);
    fillsegment(&seg);
    s[i] = seg;
  }
  double dest;
  for (i = 1; i <= n; i++) {
    dest = dest_pointseg(&pa, &s[i - 1]);
    if (dest <= a) {
      g[0][i] = dest;
      g[i][0] = dest;
    }
    dest = dest_pointseg(&pb, &s[i - 1]);
    if (dest <= a) {
      g[n + 1][i] = dest;
      g[i][n + 1] = dest;
    }
    for (j = i + 1; j <= n; j++) {
      dest = dest_segseg(&s[j - 1], &s[i - 1]);
      if (dest <= a) {
        g[j][i] = dest;
        g[i][j] = dest;
      }
    }
  }
  dest = dest_points(&pa, &pb);
  if (dest <= a) {
    g[0][n + 1] = dest;
    g[n + 1][0] = dest;
  }
  std::vector<double> d(1002, 1E+9), p(1002);
  std::vector<bool> u(1002, false);
  d[0] = 0;
  int v, minv;
  for (i = 0; i <= n + 1; i++) {
    v = -1;
    for (j = 0; j <= n + 1; j++) {
      if (!u[j] && (v == -1 || d[j] < d[v])) v = j;
    }
    if (d[v] == 1E+9) break;
    u[v] = true;
    for (j = 0; j <= n + 1; j++) {
      if (!g[v][j]) continue;
      if ((d[v] + 1 < d[j]) || (d[v] + 1 == d[j] && g[p[j]][j] > g[v][j])) {
        d[j] = d[v] + 1;
        p[j] = v;
      }
    }
  }
  if (d[n + 1] == 1E+9) {
    printf("-1\n");
  } else {
    printf("%.11f\n", (d[n + 1] - 1) * (a + b) + g[p[n + 1]][n + 1]);
  }
  return 0;
}
