public static void main(String[] args) { Scanner input=new Scanner(System.in); int n=input.nextInt(); int L=input.nextInt(); int[][] nums=new int[n][2]; int ce=0; while(ce<n) { nums[ce][0]=input.nextInt(); nums[ce][1]=input.nextInt(); ce++; } System.out.println(guidenum(nums,L)); } public static int guidenum(int[][] nums,int L) { int count=0; Arrays.sort(nums,(a,b)->a[0]-b[0]); int start=0,end=0; for(int i=0;start<L;) { for(;i<nums.length&&nums[i][0]<=start;i++) end=Math.max(end,nums[i][1]); if(start==end)return -1; start=end; count++; } return count; }