/* Clearink */

#include <queue>
#include <cstdio>
#include <algorithm>

#define rep( i, l, r ) for ( int i = l, repEnd##i = r; i <= repEnd##i; ++i )
#define per( i, r, l ) for ( int i = r, repEnd##i = l; i >= repEnd##i; --i )

inline int rint() {
	int x = 0, f = 1, s = getchar();
	for ( ; s < '0' || '9' < s; s = getchar() ) f = s == '-' ? -f : f;
	for ( ; '0' <= s && s <= '9'; s = getchar() ) x = x * 10 + ( s ^ '0' );
	return x * f;
}

template<typename Tp>
inline void wint( Tp x ) {
	if ( x < 0 ) putchar( '-' ), x = -x;
	if ( 9 < x ) wint( x / 10 );
	putchar( x % 10 ^ '0' );
}

const int MAXN = 1.5e3;
int n, m, a[MAXN + 5][MAXN + 5], b[MAXN + 5][MAXN + 5];
int d[MAXN + 5], ocnt, opt[MAXN + 5], p[MAXN + 5], q[MAXN + 5], tmp[MAXN + 5];
bool era[MAXN + 5];
std::queue<int> que;

int main() {
	n = rint(), m = rint();
	rep ( i, 1, n ) rep ( j, 1, m ) a[i][j] = rint();
	rep ( i, 1, n ) rep ( j, 1, m ) b[i][j] = rint();
	rep ( i, 2, n ) rep ( j, 1, m ) d[j] += b[i - 1][j] > b[i][j];
	rep ( i, 1, m ) if ( !d[i] ) que.push( i );
	while ( !que.empty() ) {
		int c = que.front(); que.pop();
		opt[++ocnt] = c;
		rep ( i, 2, n ) if ( b[i - 1][c] < b[i][c] && !era[i] ) {
			era[i] = true;
			rep ( j, 1, m ) if ( b[i - 1][j] > b[i][j] && !--d[j] ) {
				que.push( j );
			}
		}
	}
	rep ( i, 1, n ) q[i] = i;
	per ( k, ocnt, 1 ) {
		rep ( i, 1, n ) p[i] = i;
		std::sort( p + 1, p + n + 1, [=]( const int i, const int j ) {
			int u = a[q[i]][opt[k]], v = a[q[j]][opt[k]];
			return u != v ? u < v : i < j;
		} );
		rep ( i, 1, n ) tmp[i] = q[i];
		rep ( i, 1, n ) q[i] = tmp[p[i]];
	}
	rep ( i, 1, n ) rep ( j, 1, m ) if ( a[q[i]][j] != b[i][j] ) {
		return puts( "-1" ), 0;
	}
	wint( ocnt ), putchar( '\n' );
	per ( i, ocnt, 1 ) wint( opt[i] ), putchar( i > 1 ? ' ' : '\n' );
	return 0;
}

