This page is still under construction.

Parts of this page are still being built. What you see may change.

Shibuya Crossing

Time limit1sMemory limit256 MB

Summary
Given the list of crossing path pairs, find the size of the largest group of people whose paths all cross each other.
Level

Hard8 of 10

Topics
Graph, Dynamic programming, Geometry
Solved
No attempts yet

Problem

The scramble crossing in Shibuya, Tokyo carries so much foot traffic that people bump into each other. Model the crossing as a convex polygon. The nn people who are about to cross start at points on the lower half of the polygon's boundary. When the light changes, each person walks toward a distinct point on the upper half of the boundary. A path can wander like a strand of spaghetti and may even meet itself, but it never leaves the polygon, and two different paths never meet more than once.

Oskar watches the crossing from a cafe nearby. He has numbered the people 11 through nn in counter-clockwise order, starting with the person standing farthest to the left. He does not know which route anyone takes, but he has worked out exactly which pairs of paths cross, and that information agrees with an arrangement that can really happen.

By Murphy's law, everyone who can bump into someone does, so two people whose paths cross always bump into each other. After all nn people have crossed, find the size of the largest group of people in which every two members have bumped into each other.

A drawing of one situation that can produce the first example.

Input

The first line contains the number of people at the crossing nn (1≤n≤8001 \le n \le 800) and the number of crossing path pairs mm (0≤m≤100000 \le m \le 10000).

Each of the next mm lines contains two integers aa and bb (1≤a<b≤n1 \le a < b \le n), meaning that the path of person aa crosses the path of person bb. No pair is given twice.

Output

Print one integer, the size of the largest group of people in which every two members have bumped into each other.

Examples3

  1. Example 1

    Input
    3 1
    1 2
    
    Expected output
    2
    
  2. Example 2

    Input
    5 7
    1 3
    1 5
    1 4
    2 4
    3 4
    2 5
    2 3
    
    Expected output
    3
    
  3. Example 3

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