#include <vector>
#include<string>
#include<fstream>
#include<stdlib.h>
using namespace std;
int main()
{
	vector <int> dm(1000000,0);
	vector <int> dn(1000000,0);
	int n,m,s,hm,hn;
	int dem=0;
	long long int maxn=0,maxm=0;
	ifstream fi("DAYCHUNG.inp");
	ofstream fo("DAYCHUNG.out");
	fi>>n>>m;
	for(int i=0;i<n;i++)
	{
		fi>>s;
		dn[s]++;
		if(maxn<s)
		{
			maxn=s;
		}
	}
	for(int j=0;j<n;j++)
	{
		fi>>s;
		dm[s]++;
		if(maxm<s)
		{
			maxm=s;
		}
	}
	for(int x=0;x<=maxn;x++)
	{
		hm=dm[x];
		hn=dn[x];
		while((hm>0)&&(hn>0))
		{
			dem++;
			hm--;
			hn--;
		}
	}
	fo<<dem<<endl;
	for(int y=0;y<=maxn;y++)
	{
		while((dm[y]>0)&&(dn[y]>0))
		{
			fo<<y<<" ";
			dm[y]--;
			dn[y]--;
		}
	}
	fi.close();
	fo.close();
	return 0;
}
