# Arup Guha
# 3/8/2025
# Solution to Kattis Problem: Pencil Crayons

# Get basic input.
toks = input().split()
nBoxes = int(toks[0])
numColors = int(toks[1])

res = 0

# Go through the boxes.
for i in range(nBoxes):

    # Mapping colors to frequency.
    mymap = {}

    # Storing unique colors.
    items = set()
    toks = input().split()

    # Go through the colors in the box.
    for x in toks:

        # Update set.
        items.add(x)

        # Appropriately update frequency.
        if x in mymap:
            mymap[x] += 1
        else:
            mymap[x] = 1

    # All extra colors need to be moved.
    for x in items:
        if mymap[x] > 1:
            res += (mymap[x]-1)

# Ta da!
print(res)
