public static int closestPoint(ArrayList<Point> points) {
        Point min = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);
        int index = 0;
        for (Point point : points) {
            if (point.getY() < min.getY()) {
                min = point;
                index = points.indexOf(point);
            } else if (point.getY() == min.getY()) {
                if (point.getX() < min.getX()) {
                    min = point;
                    index = points.indexOf(point);
                }
            }
        }
        return index;
    }