import java.util.*;

class node {

	public int data;
	public node left;
	public node right;
	
	public node(int val) {
		data = val;
		left = null;
		right = null;
	}
	
	public void insert(int val) {
		
		// Base case left.
		if (val < data && left == null) {
			left = new node(val);
			return;
		}
		
		// Base case right.
		if (val >= data && right == null) {
			right = new node(val);
			return;
		}
		
		// recurse left
		if (val < data) left.insert(val);
		else			right.insert(val);
	}
	
	public void preorder() {
		System.out.print(data+" ");
		if (left != null) left.preorder();
		if (right != null) right.preorder();
	}
	
	public void inorder() {
		if (left != null) left.inorder();
		System.out.print(data+" ");
		if (right != null) right.inorder();
	}	
	
	public void postorder() {
		if (left != null) left.postorder();
		if (right != null) right.postorder();
		System.out.print(data+" ");
	}

	public int height() {
		if (left == null && right == null) return 0;
		int leftSub = left == null ? -1 : left.height();
		int rightSub = right == null ? -1 : right.height();
		return 1 + Math.max(leftSub, rightSub);
	}
	
	public int maxSumWOAncestor() {
		
		int leftSum = left == null ? 0 : left.maxSumWOAncestor();
		int rightSum = right == null ? 0 : right.maxSumWOAncestor();
		
		return Math.max(data, leftSum + rightSum);
	}
	
	public boolean isomorphic(node other) {
		
		if ((left == null) != (other.left == null)) return false;
		if ((right == null) != (other.right == null)) return false;
		
		boolean res = left == null ? true : left.isomorphic(other.left);
		if (!res) return false;
		if (right != null) res = res && right.isomorphic(other.right);
		return res;
	}
}

public class ceiling {
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		int numTrees = stdin.nextInt();
		int numNodes = stdin.nextInt();
		node[] trees = new node[numTrees];
		
		for (int i=0; i<numTrees; i++) {
			int root = stdin.nextInt();
			trees[i] = new node(root);
			for (int j=0; j<numNodes-1; j++)
				trees[i].insert(stdin.nextInt());
		}
		
		int res = 0;
		boolean[] used = new boolean[numTrees];
		for (int i=0; i<numTrees; i++) {
			if (!used[i]) {
				res++;
				for (int j=i+1; j<numTrees; j++) {
					if (trees[i].isomorphic(trees[j]))
						used[j] = true;
				}
			}
		}
		
		System.out.println(res);
	}
}