#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
vector<int> a(n * m), ans;
for (int& x : a)
cin >> x;
sort(a.begin(), a.end());
for (int i = 0; i < n * m - 1; i++)
if (a[i] == a[i + 1])
ans.push_back(a[i]);
int k = ans.size();
cout << k << "\n";
for (int x : ans)
cout << x << " ";
cout << "\n";
return 0;
}