<script>
function solution(arr){
let answer = 0;
arr.sort((a,b)=>{
if(a[0] === b[0]) return a[1]-b[1];
else return a[0] - b[0];
})
let time = Number.MIN_SAFE_INTEGER;
for(let x of arr){
if(x[0] > time) {
time = x[1];
answer++;
}
}
return answer;
}
let arr=[[14, 18], [12, 15], [15, 20], [20, 30], [5, 15]];
console.log(solution(arr));
</script>