function main(input) {
    var array = input.split('\n');
    var islands = array[0][0];
    array.shift();
    var bridgeList = [];
    var cut = 0;

    for(var i = 0; i < array.length; i++){
        bridgeList[i]=[];
        for(var j = array[i][0]; j < array[i][2]; j++){
            bridgeList[i].push(parseInt(j));
        }
    }

    while(bridgeList.length > 0){
        var duplicationList = [];
        cut++;
        for(var i = 1; i < islands; i++){
            var counter = 0;
            for(var j = 0; j< bridgeList.length; j++){
                if(bridgeList[j].indexOf(i) >=0 ){
                    counter++;
                }
            }
            duplicationList.push(counter);
        }
    
        var deleteNumber = duplicationList.indexOf(Math.max.apply(null,duplicationList)) + 1;
    
        for(var i = 0; i < bridgeList.length; i++){
            if(bridgeList[i].indexOf(deleteNumber) >=0){
                bridgeList.splice(i, 1);
                i--;
            }
        }
    }
    console.log(cut);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));