#include<bits/stdc++.h>
using namespace std;
const int N=1505;
int n,m,a[N][N],b[N][N],f1[N],f2[N],v[N][N],cnt[N],flag[N];
vector<int> v1[N],v2[N],ans;
int cmp1(int x,int y){
	for (int i=1;i<=m;i++)
		if (a[x][i]!=a[y][i])return a[x][i]<a[y][i];
	return x<y;
}
int cmp2(int x,int y){
	for (int i=1;i<=m;i++)
		if (b[x][i]!=b[y][i])return b[x][i]<b[y][i];
	return x<y;
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)scanf("%d",&a[i][j]);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)scanf("%d",&b[i][j]);
	for (int i=1;i<=n;i++)f1[i]=f2[i]=i;
	sort(f1+1,f1+n+1,cmp1);
	sort(f2+1,f2+n+1,cmp2);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			if (a[f1[i]][j]!=b[f2[i]][j]){
				puts("-1");
				return 0;
			}
	for (int i=1;i<=n;i++)b[f2[i]][m+1]=f1[i];
	int num=0;
	for (int i=1;i<n;i++){
		int Flag=0;
		for (int j=1;j<=m;j++)
			if (b[i][j]<b[i+1][j])v1[i].push_back(j),v[i][j]=1;
			else if (b[i][j]>b[i+1][j])v2[i].push_back(j),cnt[j]++,v[i][j]=-1;
			else Flag++;
		if (b[i][m+1]<b[i+1][m+1]||Flag==m)flag[i]=1;
		else num++;
	}
	while (num){
		int vis=0;
		for (int i=1;i<=m;i++)
			if (!cnt[i]){
				vis=1;
				for (int j=1;j<n;j++)
					if (flag[j]>=0&&v[j][i]){
						if (!flag[j])num--;
						flag[j]=-1;
						for (int k=1;k<=m;k++)
							if (v[j][k]==-1)cnt[k]--;
					}
				cnt[i]=-1;
				ans.push_back(i);
				break;
			}
		if (!vis){
			puts("-1");
			return 0;
		}
	}
	printf("%d\n",(int)ans.size());
	for (int i=ans.size()-1;i>=0;i--)printf("%d ",ans[i]);
}