#include<bits/stdc++.h>
using namespace std;
#define N 1505
int read(){
	int w=0,f=1;
	char c=' ';
	while(c<'0'||c>'9')c=getchar(),f=c=='-'?-1:f;
	while(c>='0'&&c<='9')w=w*10+c-48,c=getchar();
	return w*f;
}
int n,m,tot[N],in[N],ans[N],cnt;
bool vis[N<<1];
vector<int>a[N],b[N],e[N<<1];
map<vector<int>,queue<int> >mp;
signed main(){
	n=read(),m=read();
	for(int i=1;i<=n;i++){
		a[i].resize(m+1);
		for(int j=0;j<m;j++)
			a[i][j]=read();
		mp[a[i]].push(i);
	}
	for(int i=1;i<=n;i++){
		b[i].resize(m+1);
		for(int j=0;j<m;j++)
			b[i][j]=read();
		if(mp[b[i]].empty())return puts("-1"),0;
		int tmp=mp[b[i]].front();
		mp[b[i]].pop();
		b[i][m]=tmp;
	}
	for(int i=1;i<n;i++)
		for(int j=0;j<=m;j++)
			if(b[i][j]>b[i+1][j])e[m+i].push_back(j),in[j]++;
			else if(b[i][j]<b[i+1][j])e[j].push_back(m+i),in[m+i]++;
	queue<int>q;
	for(int i=0;i<=m;i++)
		if(!in[i])vis[i]=1,q.push(i);
	cnt=0;
	while(!q.empty()&&!vis[m]){
		int u=q.front();
		q.pop();
		if(u<=m){
			ans[++cnt]=u+1;
			for(auto v:e[u])
				if(!vis[v])vis[v]=1,q.push(v);
		}
		else{
			for(auto v:e[u]){
				in[v]--;
				if(!in[v])vis[v]=1,q.push(v);
			}
		}
	}
	if(!vis[m])return puts("-1"),0;
	printf("%d\n",cnt);
	for(int i=cnt;i>0;i--)
		printf("%d%c",ans[i],i==1?'\n':' ');
	return 0;
}