Dimensional Debugging

아직 제출이 없습니다시간 제한2초메모리 제한2048 MB

문제

After struggling with this one problem for days, you have had enough! You are determined to find the bug in your algorithm once and for all! To do so, you will start all over. From scratch. At least you are sure you know the correct answer in the most trivial case: the answer in (0,0,,0)(0,0, \dots, 0) is 00.

You will re-solve the problem, which takes kk parameters, using nn simpler but slower algorithms. Each algorithm has two bounds for every parameter ii (L_iL\_i and H_iH\_i). An algorithm is only fast enough to run on inputs (x_1,,x_k)(x\_1, \dots, x\_k) where x_iH_ix\_i \leq H\_i for all parameters ii. You are confident the implementation of an algorithm is correct if you can verify its correctness at least once on an input (x_1,,x_k)(x\_1, \dots, x\_k) where x_iL_ix\_i \geq L\_i for all parameters ii. To do so, you will need another algorithm that you already proved to be correct and can handle such large inputs, or your knowledge of the answer for (0,0,,0)(0,0, \dots, 0).

Given a list of algorithms and their bounds, find the number of algorithms you are sure are correctly implemented.

As an example, consider the first sample case shown in Figure D.1 on the left. The first algorithm (red, bottom left) can be used to verify the correctness of the second (yellow, top left) and third (blue, bottom right) algorithms. No algorithm can be used to verify the correctness of the fourth algorithm (grey, top right).

Figure D.1: The algorithms to be tested in samples 1 and 2, respectively. The boxes indicate the parameters where an algorithm must be tested, while the lighter background indicates the region where an algorithm can be used to verify other algorithms.

입력

The input consists of:

  • One line with two integers nn and kk (1n10001\leq n\leq 1000, 1k101\leq k\leq 10), the number of algorithms to test and the number of parameters.

  • Then follow nn pairs of lines:

    • One line with kk integers L_i,,L_kL\_i, \dots, L\_k (0L_i1090\leq L\_i \leq 10^9 for all ii).
    • One line with kk integers H_1,,H_kH\_1, \dots, H\_k (0H_i1090\leq H\_i \leq 10^9 for all ii).
  • It is guaranteed that L_iH_iL\_i \leq H\_i for all 1ik1 \leq i\leq k.

출력

Output the number of algorithms of which you can verify the correctness.