#include<fstream>
#include<string>
#include<vector>
using namespace std;
int main()
{
	ifstream fi("DC.inp");
	ofstream fo("DC.out");
	int m,n;
	fi>>n>>m;
	vector <int> sm(1000000,0);
	vector <int> sn(1000000,0);
	int chung=0;
	int max=0;
	int kq[n];
	int s;
	for(int i=0;i<n;i++)
	{
		fi>>s;
		if(s>max)
		{
			max=s;
		}
		sn[s]++;
	}
	for(int j=0;j<m;j++)
	{
		fi>>s;
		sm[s]++;
	}
	for(int x=0;x<=max;x++)
	{
		while((sn[x]>0)&&(sm[x]>0))
		{
			kq[chung]=x;
			sn[x]--;
			sm[x]--;
			chung++;
		}
	}
	fo<<chung<<endl;
	for(int y=0;y<chung;y++)
	{
		fo<<kq[y]<<" ";
	}
	fi.close();
	fo.close();
	return 0;
}
