1 /*Author:WNJXYK*/
2 #include<cstdio>
3 #include<iostream>
4 #include<cstring>
5 #include<string>
6 #include<algorithm>
7 #include<queue>
8 #include<set>
9 #include<bitset>
10 #include<cstdlib>
11 #include<ctime>
12 #include<cmath>
13 #include<map>
14 using namespace std;
15
16 #define LL long long
17 #define Inf 2147483647
18 #define InfL 10000000000LL
19
20 inline int abs(int x){if (x<0) return -x;return x;}
21 inline int abs(LL x){if (x<0) return -x;return x;}
22 inline void swap(int &x,int &y){int tmp=x;x=y;y=tmp;}
23 inline void swap(LL &x,LL &y){LL tmp=x;x=y;y=tmp;}
24 inline int remin(int a,int b){if (a<b) return a;return b;}
25 inline int remax(int a,int b){if (a>b) return a;return b;}
26 inline LL remin(LL a,LL b){if (a<b) return a;return b;}
27 inline LL remax(LL a,LL b){if (a>b) return a;return b;}
28 inline void read(int &x){x=0;int f=1;char ch=getchar();while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}x=x*f;}
29 inline void read(LL &x){x=0;LL f=1;char ch=getchar();while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}x=x*f;}
30 inline void read(int &x,int &y){read(x);read(y);}
31 inline void read(LL &x,LL &y){read(x);read(y);}
32 inline void read(int &x,int &y,int &z){read(x,y);read(z);}
33 inline void read(int &x,int &y,int &n,int &m){read(x,y);read(n,m);}
34 inline void read(LL &x,LL &y,LL &z){read(x,y);read(z);}
35 inline void read(LL &x,LL &y,LL &n,LL &m){read(x,y);read(n,m);}
36
37 const int Maxf=10000;
38 struct Node{
39 int x,y;
40 };
41 Node p[Maxf+10];
42 int h,f;
43
44 struct Edge{
45 int v;
46 int dist;
47 int nxt;
48 Edge(){}
49 Edge(int a,int b,int c){v=a;dist=b;nxt=c;}
50 };
51 const int Maxn=5000000;
52 Edge e[Maxn+10];
53 int head[Maxf+10];
54 int nume;
55 inline void addEdge(int x,int y,int dist){
56 e[++nume]=Edge(y,dist,head[x]);
57 head[x]=nume;
58 e[++nume]=Edge(x,dist,head[y]);
59 head[y]=nume;
60 }
61 inline int getDist(Node a,Node b){
62 return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
63 }
64 const int mDist=1000000;
65
66 queue<int> que;
67 bitset<Maxf+10> inque;
68 int dist[Maxf+10];
69 inline void SPFA(int src){
70 inque.reset();
71 memset(dist,127,sizeof(dist));
72 que.push(src);
73 inque[src]=true;
74 dist[src]=0;
75 while(!que.empty()){
76 int now=que.front();
77 que.pop();
78 for (int i=head[now];i;i=e[i].nxt){
79 int v=e[i].v;
80 int w=e[i].dist;
81 if (dist[v]>dist[now]+w){
82 dist[v]=dist[now]+w;
83 if (inque[v]==false){
84 inque[v]=true;
85 que.push(v);
86 }
87 }
88 }
89 inque[now]=false;
90 }
91
92 }
93
94 int main(){
95 read(h,f);
96 for (int i=1;i<=f;i++) read(p[i].x,p[i].y);
97 for (int i=1;i<f;i++){
98 for (int j=i+1;j<=f;j++){
99 int tDist=getDist(p[i],p[j]);
100 if (tDist<=mDist){
101 addEdge(i+1,j+1,1);
102 //cout<<i<<" "<<j<<endl;
103 }
104 }
105 }
106
107 //cout<<nume<<endl;
108 for (int i=1;i<=f;i++){
109 if (h-1000<=p[i].y){
110 addEdge(1,i+1,0);
111 //cout<<0<<" "<<i<<endl;
112 }
113 if (p[i].y<=1000){
114 addEdge(i+1,f+2,0);
115 //cout<<i<<" "<<f+1<<endl;
116 }
117 }
118
119 SPFA(1);
120
121 cout<<dist[f+2]+1<<endl;
122
123 return 0;
124 }