Under construction

Still being built. Things may change

Formula Flatland

Time limit3sMemory limit1024 MB

Summary
Given a planar road network with crossing coordinates, find the fewest crossings that can form a simple closed cycle.
Level

Hard8 of 10

Topics
Graph, BFS, Geometry
Solved
No attempts yet

Problem

Flatland is hosting the Formula One Grand Prix of Flatland for the first time. Like many other cities, Flatland cannot build a dedicated circuit for the race, so it will close some of its normal streets and crossings to form one. You organized last year's Flatland Olympics, so you were hired to find a suitable circuit. Closed streets annoy the residents, so you want to minimize the number of crossings that must be closed.

Figure F.1: Visualization of the second sample. One possible optimal circuit is (4,5,7,6)(4,5,7,6).

Your job is to select some road segments that form a circle while touching as few crossings as possible. All roads in Flatland are bidirectional, but during the race they can only be used in one direction for safety reasons.

Input

The first line contains two integers nn and mm (4≤n≤1054\leq n \leq 10^5, 5≤m≤3⋅1055\leq m \leq 3\cdot 10^5), the number of crossings and the number of road segments.

Each of the next nn lines contains two integers xx and yy (0≤x,y≤1090\leq x,y\leq 10^9), the position of a crossing on the map. No two crossings share a position.

Each of the next mm lines contains two integers aa and bb (1≤a,b≤n1\leq a,b\leq n, a≠ba\neq b), meaning that crossings aa and bb are connected by a road segment. Two crossings are connected by at most one road segment.

Road segments only intersect at crossings they both start or end at. Every crossing has at least three road segments meeting at it.

Output

Print a single integer, the minimum number of crossings the racetrack must contain.

Examples2

  1. Example 1

    Input
    4 6
    0 0
    3 0
    0 3
    1 1
    1 2
    1 3
    1 4
    2 3
    2 4
    3 4
    
    Expected output
    3
    
  2. Example 2

    Input
    10 15
    1 5
    2 1
    3 4
    4 2
    5 3
    6 2
    7 3
    8 1
    9 4
    11 5
    1 2
    1 3
    1 10
    2 4
    3 5
    4 5
    4 6
    5 7
    6 7
    6 8
    7 9
    8 10
    9 10
    2 8
    3 9
    
    Expected output
    4