#include<bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
// 定义一个图的邻接表,键是节点,值是与该节点相连的节点列表
map<int,vector<int> > g;
// 定义一个集合,用于存储可以到达的终点
set<int> ans;
// 定义两个整数,n表示网格的大小,m表示黑棋的数量
int n,m;
int main()
{
// 输入网格大小n和黑棋数量m
cin >> n >> m;
// 输入每个黑棋的位置,并将其存储在图中
for(int i = 1; i <= m; i++)
{
int x,y;
cin >> x >> y;
g[x].push_back(y);
}
// 将终点n插入到可到达集合中
ans.insert(n);
// 遍历图中的每个节点
for(auto it : g)
{
int x = it.first;
vector<int> t1,t2;
// 遍历与节点x相连的每个节点y
for(int y : g[x]){
// 如果y在可到达集合中,将其加入t1
if(ans.count(y)) t1.push_back(y);
// 如果y的相邻节点在可到达集合中,将其加入t2
if(ans.count(y + 1) || ans.count(y - 1)) t2.push_back(y);
}
// 从可到达集合中移除t1中的节点
for(int y : t1){
ans.erase(y);
}
// 将t2中的节点加入到可到达集合中
for(int y : t2){
ans.insert(y);
}
}
// 输出可到达集合的大小,即可以到达的终点数量
cout << ans.size();
return 0;
}