import java.util.*;
import java.io.*;
import java.text.*;

class Algorithm {
    ArrayList<Integer> L;
    ArrayList<Integer> H;

    public Algorithm(ArrayList<Integer> L, ArrayList<Integer> H) {
        this.L = L;
        this.H = H;
    }

    public boolean covers(Algorithm other) {
        for (int i = 0; i < L.size(); i++) {
            if (other.L.get(i) > this.H.get(i)) {
                return false;
            }
        }

        return true;
    }
}

public class NickyEnMark{
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        Set<Algorithm> algorithms = new HashSet<>();
        for (int i = 0; i < n; i++) {
            ArrayList<Integer> L = new ArrayList<>();
            for (int j = 0; j < k; j++) {
                L.add(scanner.nextInt());
            }
            ArrayList<Integer> H = new ArrayList<>();
            for (int j = 0; j < k; j++) {
                H.add(scanner.nextInt());
            }

            algorithms.add(new Algorithm(L, H));
        }

        Set<Algorithm> solvable = new HashSet<>();
        Set<Algorithm> lastLoop = new HashSet<>();
        ArrayList<Integer> zeroL = new ArrayList<>();
        for (int j = 0; j < k; j++) {
            zeroL.add(0);
        }
        ArrayList<Integer> zeroH = new ArrayList<>();
        for (int j = 0; j < k; j++) {
            zeroH.add(0);
        }
        lastLoop.add(new Algorithm(zeroL, zeroH));

        while (!lastLoop.isEmpty()) {
            Set<Algorithm> newLastLoop = new HashSet<>();
            for (Algorithm a : lastLoop) {
                for (Algorithm b : algorithms) {
                    if (a.covers(b)) {
                        newLastLoop.add(b);
                        solvable.add(b);
                    }
                }
            }

            algorithms.removeAll(newLastLoop);

            lastLoop = newLastLoop;

        }

        System.out.println(solvable.size());
    }
}