h, n = gets.split.map(&:to_i)

obs = {}
n.times do
    x, y = gets.split.map(&:to_i)
    (obs[y] ||= []) << x
end

tab = Array.new(2**8, -Float::INFINITY)
k = 0b11110000
(obs[0] || []).each do |i|
    k |= (1 << i)
end
tab[k] = 0

(1..h-1).each do |i|
    new_tab = Array.new(2**8, -Float::INFINITY)
    b1 = 0
    (obs[i] || []).each do |j|
        b1 |= (1 << j)
    end
    (0..2**8-1).each do |b2|
        x = ((b2 & 0b1111) << 4) | b1
        new_tab[x] = tab[b2] if tab[b2] > new_tab[x]
        pattern = 0b00110011
        3.times do
            if x & pattern == 0
                y = (x | pattern)
                c = tab[b2] + 1
                new_tab[y] = c if c > new_tab[y]
            end
            pattern <<= 1
        end
        pattern = 0b11111111
        if x & pattern == 0
            y = (x | pattern)
            c = tab[b2] + 2
            new_tab[y] = c if c > new_tab[y]
        end
    end
    tab = new_tab
end
p tab.max

