#include<bits/stdc++.h> usingnamespace std; #ifdef LOCAL #define debug(...) fprintf(stdout, ##__VA_ARGS__) #else #define debug(...) void(0) #endif #define int long long inlineintread(){int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+ (x<<3)+(ch^48);ch=getchar();}return x*f;} #define Z(x) (x)*(x) #define pb push_back #define fi first #define se second //#define M #define mo 100007 #define N 50010 structnode { int x, y; }a[N]; int b[N], f0, f1, ans; int n, m, i, j, k, T, x;
structBinay_tree { int cnt[N]; voidadd(int x, int k){ while(x < N) (cnt[x] += k) %= mo, x += x & -x; } intcha(int x){ int ans = 0; while(x) (ans += cnt[x]) %= mo, x -= x & -x; return ans; } intqry(int o, int x){ if(!o) returncha(x); returncha(n) - cha(x); } }Bin[11][2];
signedmain() { #ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif // srand(time(NULL)); // T=read(); // while(T--) { // // } n = read(); m = read(); for(i = 1; i <= n; ++i) a[i].x = read(), a[i].y = b[i] = read(); sort(a + 1, a + n + 1, [] (node x, node y) { return x.x < y.x; }); sort(b + 1, b + n + 1); for(i = 1; i <= n; ++i) a[i].y = lower_bound(b + 1, b + n + 1, a[i].y) - b; for(i = 1; i <= n; ++i) { x = a[i].y; // printf("# %d\n", x); for(k = m; k >= 1; --k) { f0 = f1 = 0; f0 = Bin[k][0].qry(0, x); f1 = Bin[k][1].qry(1, x); f0 += Bin[k - 1][1].qry(0, x); f1 += Bin[k - 1][0].qry(1, x); Bin[k][0].add(x, f0); Bin[k][1].add(x, f1); } Bin[0][0].add(x, 1); Bin[0][1].add(x, 1); } ans = Bin[m][0].cha(n) + Bin[m][1].cha(n); printf("%lld", (ans % mo + mo) % mo); return0; }