The Climbing Wall
题号:NC25140
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 32 M,其他语言64 M
64bit IO Format: %lld

题目描述

One of the most popular attractions at the county fair is the climbing wall. Bessie wants to plan her trip up the wall in advance and needs your help.
The wall is 30,000 millimeters wide and H (1001 <= H <= 30,000) millimeters high and has F (1 <= F <= 10,000) hoof-holds at unique X,Y coordinates expressed in millimeters. 0,0 is at the ground level on the left side of the wall. Hoof-holds are separated by at least 300 millimeters since no cow can maneuver them if they are spaced too close! Bessie knows there is at least one way up.
Bessie, through techniques only she knows, uses successive single hoof-holds to climb the wall. She can only move from one hoof-hold to another if they are no more than one meter apart. She can, of course, move up, down, right, left or some combination of these in each move. Similarly, once she gets to a hoof-hold that is at least H-1000 millimeters above the ground, she can nimbly climb from there onto the platform atop the wall. Bessie can start at any X location that has a Y location <= 1000 millimeters.
Given the height of the wall and the locations of the hoof-holds, determine the smallest number of hoof-holds Bessie should use to reach the top.

输入描述:

Line 1: Two space-separated integers, H and F.
Lines 2..F+1: Each line contains two space-separated integers (respectively X and Y) that describe a hoof-hold. X is the distance from the left edge of the climbing wall; Y is the distance from the ground.

输出描述:

Line 1: A single integer that is the smallest number of hoof-holds Bessie must use to reach the top of the climbing wall.
示例1

输入

复制
3000 5
600 800
1600 1800
100 1300
300 2100
1600 2300

输出

复制
3

说明

The wall is three meters high with 5 hoof-holds.
Bessie can start on the ground, move to the hoof-hold at (600,800), move from there to (100,1300), move from there to (300,2100), and from that high height can hop onto the platform. This trip requires three hoof-holds. There is no shorter path that Bessie can take.