// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

int board[10010][4], dp[3][1 << 8];

int main() {
    int H, N; cin >> H >> N;
    const int W = 4;
    for(int i=0; i<N; i++) {
        int x, y; cin >> y >> x;
        board[H-1-x][W-1-y] = 1;
    }

    /*
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            cerr << board[i][j] << " ";
        }
        cerr << endl;
    }
    */

    int init_bit = 0;
    for(int i=0; i<2; i++) {
        for(int j=0; j<W; j++) {
            int k = i * 4 + j;
            init_bit |= (board[i][j] << k);
        }
    }

    fill(dp[0], dp[2], -INF);
    dp[0][init_bit] = 0;
    // cerr << bitset<8>(init_bit).to_string() << endl;
    for(int i=0; i+1<H; i++) {
        for(int j=0; j<W; j++) {
            int k = i * 4 + j;
            int cur = k % 2, nxt = 1 - cur;
            for(int bit=0; bit<(1<<8); bit++) {
                if(dp[cur][bit] == -INF) continue;
                // fprintf(stderr, "cur = %d (%d), bit = %s: dp = %d\n", cur, k, bitset<8>(bit).to_string().c_str(), dp[cur][bit]);
                chmax(dp[nxt][bit], dp[cur][bit]);
                for(int x=0; x<3; x++) {
                    bool ng = false;
                    ng |= (bit >> (4 + x + 0) & 1);
                    ng |= (bit >> (4 + x + 1) & 1);
                    ng |= (bit >> (0 + x + 0) & 1);
                    ng |= (bit >> (0 + x + 1) & 1);

                    if(ng) continue;
                    int nbit = bit;
                    nbit |= (1 << (4 + x + 0));
                    nbit |= (1 << (4 + x + 1));
                    nbit |= (1 << (0 + x + 0));
                    nbit |= (1 << (0 + x + 1));
                    chmax(dp[nxt][nbit], dp[cur][bit] + 1);
                }
                dp[cur][bit] = -INF;
            }
        }

        swap(dp[0], dp[1]);
        /*
        for(int bit=0; bit<(1<<8); bit++) {
            for(int x=0; x<2; x++) {
                if(dp[x][bit] == -INF) continue;
                fprintf(stderr, "val: x = %d, bit = %d, %d\n", x, bit, dp[x][bit]);
            }
        }
        */
        
        // 値が入っているのは常に dp[1] のほう
        // ここのインデックスを更新して dp[1] を捨てる
        int down_bit = 0;
        for(int j=0; j<W; j++) {
            down_bit |= (board[i+2][j] << j);
        }
        // cerr << "down_bit: " << bitset<4>(down_bit).to_string() << endl;

        for(int bit=0; bit<(1<<8); bit++) {
            int nbit = (bit >> 4) | (down_bit << 4);
            chmax(dp[0][nbit], dp[1][bit]);
            // if(dp[1][bit] != -INF) fprintf(stderr, "nbit = %s (%d), val = %d\n", bitset<8>(nbit).to_string().c_str(), nbit, dp[0][nbit]);
        }

        // cerr << "hi" << endl;
        /*
        for(int bit=0; bit<(1<<8); bit++) {
            if(dp[0][bit] == -INF) continue;
            fprintf(stderr, "dp[0][%d] = %d\n", bit, dp[0][bit]);
        }
        */

        fill(dp[1], dp[1] + (1 << 8), -INF);
    }

    int ans = 0;
    for(int i=0; i<(1<<8); i++) {
        chmax(ans, dp[0][i]);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3272