//
// Written by Fyodor Menshikov 27.02.2008
// 21:38-22:21
//

import java.io.*;
import java.util.*;

class Point {

   int x;
   int y;

   Point(Scanner in) {
      x = in.nextInt();
      y = in.nextInt();
   }
}

class Line {

   int a;
   int b;
   int c;

   Line(Segment s) {
      // (x - x1)/(x2 - x1) = (y - y1)/(y2 - y1)
      // (x - x1)(y2 - y1) = (y - y1)(x2 - x1)
      // (y2 - y1)x + (x1 - x2)y + y1x2 - x1y2 = 0
      a = s.p2.y - s.p1.y;
      b = s.p1.x - s.p2.x;
      c = s.p1.y * s.p2.x - s.p1.x * s.p2.y;
   }

   int getValue(Point p) {
      return a * p.x + b * p.y + c;
   }

   boolean isPlusMinus(Segment s) {
      int value1 = getValue(s.p1);
      int value2 = getValue(s.p2);
      return value1 > 0 && value2 < 0 || value1 < 0 && value2 > 0;
   }
}

class Segment {

   Point p1;
   Point p2;
   Line line;

   Segment(Scanner in) {
      p1 = new Point(in);
      p2 = new Point(in);
      line = new Line(this);
   }

   Segment(Point p1, Point p2) {
      this.p1 = p1;
      this.p2 = p2;
      line = new Line(this);
   }

   double length() {
      int dx = p1.x - p2.x;
      int dy = p1.y - p2.y;
      return Math.sqrt(dx * dx + dy * dy);
   }

   boolean intersects(Segment second) {
      return this.line.isPlusMinus(second) && second.line.isPlusMinus(this);
   }
}

class Main {

   Scanner in;
   PrintWriter out;

   Main() {
      try {
         in = new Scanner(System.in);
         out = new PrintWriter(System.out);
      } catch (Exception e) {
         throw new Error();
      }
   }

   void asserT(boolean e) {
      if (!e) {
         throw new Error();
      }
   }

   Segment segs[];
   Point points[];

   double getDistance(int point1, int point2) {
      Segment s = new Segment(points[point1], points[point2]);
      for (int i = 0; i < segs.length; i++) {
         if (s.intersects(segs[i])) {
            return Double.POSITIVE_INFINITY;
         }
      }
      return s.length();
   }

   void run() {
      // long start = System.nanoTime();
      segs = new Segment[in.nextInt()];
      asserT(0 <= segs.length && segs.length <= 100);
      for (int i = 0; i < segs.length; i++) {
         segs[i] = new Segment(in);
      }
      points = new Point[segs.length * 2 + 2];
      points[0] = new Point(in);
      points[points.length - 1] = new Point(in);
      for (int i = 0; i < segs.length; i++) {
         points[i * 2 + 1] = segs[i].p1;
         points[i * 2 + 2] = segs[i].p2;
      }
      double distanceTo[] = new double[points.length];
      boolean isFinal[] = new boolean[points.length];
      for (int i = 0; i < points.length; i++) {
         distanceTo[i] = getDistance(0, i);
      }
      asserT(distanceTo[0] == 0);
      isFinal[0] = true;
      while (true) {
         double min = Double.POSITIVE_INFINITY;
         int minI = 0;
         for (int i = 0; i < points.length; i++) {
            if (!isFinal[i] && distanceTo[i] < min) {
               min = distanceTo[i];
               minI = i;
            }
         }
         if (minI == 0) {
            out.println("-1\n");
            break;
         }
         if (minI == points.length - 1) {
            out.printf(Locale.US, "%.4f\n", distanceTo[minI]);
            break;
         }
         asserT(!isFinal[minI]);
         isFinal[minI] = true;
         for (int i = 0; i < points.length; i++) {
            if (!isFinal[i]) {
               distanceTo[i] = Math.min(distanceTo[i], distanceTo[minI] + getDistance(minI, i));
            }
         }
      }
      // out.println((System.nanoTime() - start) / 1000000);
      out.close();
   }

   public static void main(String args[]) {
      new Main().run();
   }
}