(function(input) {
    var elems = input.split(/ |\n/);
    var n = parseInt(elems.shift());
    var m = parseInt(elems.shift());
    var counts = new Array(n);
    for (var i = 0; i < n; ++i) {
        counts[i] = 0;
    }
    for (var i = 0; i < m; ++i) {
        var a = parseInt(elems.shift());
        var x = Math.max(counts[a - 1], counts[a]) + 1;
        counts[a - 1] = counts[a] = x;
    }
    console.log(Math.max.apply(null, counts));
})(require('fs').readFileSync('/dev/stdin', 'utf8').trim());