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 = Tuple.Create(p[i].Item2, -1); int le = 0, ri = n; while (ri - le > 1) { int mid = (le + ri) / 2; if (p[i].Item2 <= p[mid].Item1) { ri = mid; } else { le = mid; } } int loc = ri; 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 mkar(int n, int val) { List res = new List(n); for(int i=0;i