# Arup Guha
# 12/14/2024
# Solution to Kattis Problem: Rock Band
# https://open.kattis.com/problems/rockband

toks = input().split()
numPeople = int(toks[0])
numSongs = int(toks[1])

# Store all preferences here.
pref =[]
for i in range(numPeople):
    mine = [int(x) for x in input().split()]
    pref.append(mine)

# List of songs ready to go.
ready = []

# Frequency array for songs (how many people want to play this one)
freq = []
for i in range(numSongs):
    freq.append(0)

# Go through rank list from top to bottom.
for i in range(numSongs):

    # Find each person's ith ranked song.
    for j in range(numPeople):

        # Update the frequency of person j's ith favorite song.
        freq[pref[j][i]-1] += 1

        # This song is ready to go.
        if freq[pref[j][i]-1] == numPeople:
            ready.append(pref[j][i])

    # See if we're ready.
    if len(ready) == i+1:
        break

# Sort and print.
ready.sort()
print(len(ready))
for x in ready:
    print(x, end=" ")
print()
