#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1005;
int N, M, dp[maxn][maxn], A[maxn], B[maxn];
int vec[maxn][maxn], c[maxn];
void init () {
scanf("%d%d", &N, &M);
for (int i = 1; i <= N; i++)
scanf("%d%d", &A[i], &B[i]);
memset(c, 0, sizeof(c));
for (int i = 0; i <= M; i++)
vec[i][c[i]++] = 0;
}
inline int find(int idx, int x) {
return lower_bound(vec[idx], vec[idx]+c[idx], x) - vec[idx];
}
inline void set(int idx, int pos, int x) {
if (pos == c[idx])
vec[idx][c[idx]++] = x;
while (pos && vec[idx][pos] >=