n, m = map(int, input().split())
matrix = [list(map(int, input().split())) for _ in range(n)]
a = [elem for row in matrix for elem in row]
a.sort()
ans = []
for i in range(n * m - 1):
if a[i] == a[i + 1]:
ans.append(a[i])
k = len(ans)
print(k)
print(*ans)