using System.Collections; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; internal class Program { private const long mod = 998244353; private const long mod17 = 1000000007; public static void Main(string[] args) { var line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int n = line[0], k = line[1]; List<(int,int)> p = new List<(int,int)>(n); for (int i = 0; i < n; i++) { line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int l = line[0], r = line[1]; p.Add((l, r)); } p.Sort(); //Console.WriteLine("hello"); for (int i = 0; i < n; i++) { //Console.WriteLine("{0},{1}",p[i].Item1,p[i].Item2); } var mir = mkar(n + 1, (int)mod17); var chkr = mkar(n + 1, n); for (int i = n - 1; i >= 0; i--) { mir[i] = mir[i + 1]; chkr[i] = chkr[i + 1]; if (mir[i] > p[i].Item2) { mir[i] = p[i].Item2; chkr[i] = i; } } List> nex = new List>(n+1); for (int i = 0; i < n+1; i++) { var ad = mkar(18, n); nex.Add(ad); } for (int i = 0; i < n; i++) { var t = (p[i].Item2, -1); var loc = ~p.BinarySearch(t, new lower_bound<(int, int)>()); //Console.WriteLine(loc); nex[i][0] = chkr[loc]; } //Console.WriteLine("hello"); nex[n][0] = n; for (int j = 0; j < 17; j++) { for (int i = 0; i < n+1; i++) { //Console.WriteLine(nex[i].Count()); nex[i][j + 1] = nex[nex[i][j]][j]; } //Console.WriteLine("Hello"); } int ans=(int)mod17; for(int i=0;i : IComparer where T : IComparable { public int Compare(T x, T y) { return 0 <= x.CompareTo(y) ? 1 : -1; } } public static List mkar(int n, int val) { List res = new List(n); for(int i=0;i