#include "bits/stdc++.h"
using namespace std;
using namespace std::chrono;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(ll i=a;i<b;++i)
#define rep(...) _overload3(__VA_ARGS__,_repi,_rep)(__VA_ARGS__)
#define _rrepi(i,a,b) for(ll i=b-1;i>=a;i--)
#define _rrep(i,n) _rrepi(i,0,n)
#define rrep(...) _overload3(__VA_ARGS__,_rrepi,_rrep)(__VA_ARGS__)
#define sum(...) accumulate(range(__VA_ARGS__),0)
#define _range(i) (i).begin(),(i).end()
#define _rangek(i,k) (i).begin(),(i).begin()+k
#define range(...) _overload3(__VA_ARGS__,a,_rangek,_range)(__VA_ARGS__)
const ll LINF=1000000000000000000;
const int INF=100000007;
const ll MOD=100000007;
#define Yes(i) out((i)?"Yes":"No")
#define vec(type,name,size) vector<type> name(size);
#define VEC(type,name,size) vector<type> name(size);in(name)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(i) ll i;in(i)
#define STR(i) string i;in(i)
#define CHR(i) char i;in(i)
#define DBL(i) double i;in(i)
struct aaa{aaa(){cin.tie(0); cout<<fixed<<setprecision(15);};}aaaaaaa;
template<typename T>
istream& operator >> (istream& is, vector<T>& vec);
template<typename T,typename L>
istream& operator >> (istream& is, pair<T,L>& p);
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec);
template<typename T,typename L>
ostream& operator << (ostream& os, pair<T,L>& p);
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){for(T& x: vec) is >> x;return is;}
template<typename T,typename L>
istream& operator >> (istream& is, pair<T,L>& p){is >> p.first;is >> p.second;return is;}
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){rep(i,vec.size()){os << vec[i] << ( i+1 == vec.size() ? "" : " " );}return os;}
template<typename T,typename L>
ostream& operator << (ostream& os, pair<T,L>& p){os << p.first << " " << p.second;return os;}
inline void in() {}
inline void in(int&& a){scanf("%d",&a);}
inline void in(ll&& a){scanf("%lld",&a);}
inline void in(double&& a){scanf("%lf",&a);}
inline void in(char&& a){scanf("%c",&a);}
template<class T>
inline void in(T&& a){cin>>a;}
template<class Head,class... Tail>
inline void in(Head&& head,Tail&&... tail){in(head);in(move(tail)...);}
inline void out(){cout<<'\n';}
inline void out(const char a[]){if(strcmp(a,"No_Break"))cout<<a<<'\n';}
template<class T>
inline void out(T a){cout<<a<<'\n';}
template<class Head,class... Tail>
inline void out(Head head,Tail... tail){cout<<head<<' ';out(move(tail)...);}
int h,n;
vector<array<int,4>>s(10001);
vector<vector<vector<vector<int>>>>mem(10000,vector<vector<vector<int>>>(2,vector<vector<int>>(2,vector<int>(2,INF))));
int dp(int y,bool a1,bool a2,bool a3){
    if(y==h)return 0;
    if(mem[y][a1][a2][a3]-INF)return mem[y][a1][a2][a3];
    int a,max;
    bool b1=s[y+2][0]+s[y+2][1]+s[y+1][0]+s[y+1][1],b2=s[y+2][2]+s[y+2][1]+s[y+1][2]+s[y+1][1],b3=s[y+2][2]+s[y+2][3]+s[y+1][2]+s[y+1][3];
    max=dp(y+1,b1,b2,b3);
    if(!a1){
        a=dp(y+1,1,1,b3)+1;
        if(max<a)max=a;
    }
    if(!a2){
        a=dp(y+1,1,1,1)+1;
        if(max<a)max=a;
    }
    if(!a3){
        a=dp(y+1,b1,1,1)+1;
        if(max<a)max=a;
    }
    if(!(a1+a3)){
        a=dp(y+1,1,1,1)+2;
        if(max<a)max=a;
    }
    mem[y][a1][a2][a3]=max;
    return mem[y][a1][a2][a3];
}
int main(){
    in(h,n);
    rep(i,n){
        INT(x,y);
        s[y][x]=1;
    }
    rep(i,4)s[h][i]=1;
    out(dp(0,s[0][0]+s[0][1]+s[1][0]+s[1][1],s[0][2]+s[0][1]+s[1][2]+s[1][1],s[0][2]+s[0][3]+s[1][2]+s[1][3]));
}










Measured memory_bytes: 7436