#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int N=1510;

int gti(void)
{
	char c=getchar();
	int ret=0,st=1;
	for (;c!='-'&&!isdigit(c);c=getchar());
	if (c=='-') st=-1,c=getchar();
	for (;isdigit(c);c=getchar()) ret=ret*10+c-'0';
	return ret*st;
}

struct H_SH
{
	ull a,b;
	H_SH operator+(const int x)const
	{
		return {a*97+x,b*998244353+x};
	}
	bool operator==(const H_SH &x)const
	{
		return a==x.a&&b==x.b;
	}
}A[N],B[N];;

struct edge{edge *nxt;int to;}pool[N*N],*pt[N<<1],*p=pool;
void addedge(int a,int b)
{
	*(++p)=(edge){pt[a],b},pt[a]=p;
}

int a[N][N],b[N][N],deg[N],q[N],st,tl;
bool vis[N],usd[N<<1];
int main(void)
{
	int n=gti(),m=gti();
	bool ans=true;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			a[i][j]=gti(),A[i]=A[i]+a[i][j];
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			b[i][j]=gti(),B[i]=B[i]+b[i][j];
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=n;j++)
			if (!vis[j]&&B[i]==A[j])
			{
				vis[j]=true,b[i][0]=j;
				break;
			}
		if (!b[i][0])
		{
			ans=false;
			break;
		}
	}
	if (ans)
	{
		for (int i=1;i<n;i++)
			for (int j=0;j<=m;j++)
			{
				if (b[i][j]<b[i+1][j])
					addedge(j,m+i);
				if (b[i][j]>b[i+1][j])
					addedge(m+i,j),++deg[j];
			}
		st=tl=-1;
		for (int i=0;i<=m;i++)
			if (!deg[i])
				q[++tl]=i;
		while (st<tl)
		{
			int now=q[++st];
			for (edge *i=pt[now];i;i=i->nxt)
				if (!usd[i->to])
				{
					usd[i->to]=true;
					for (edge *j=pt[i->to];j;j=j->nxt)
					{
						--deg[j->to];
						if (!deg[j->to])
							q[++tl]=j->to;
					}
				}
		}
		for (int i=1;i<n;i++)
			if (!usd[m+i])
				ans=false;
	}
	if (!ans) puts("-1");
	else
	{
		int k=0;
		while (k<=tl&&q[k]!=0) ++k;
		printf("%d\n",k);
		for (int i=k-1;i>=0;i--)
			printf("%d%c",q[i]," \n"[i==0]);
	}
	return 0;
}
