#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
 
#define F first
#define S second
 
const int MOD = 1e9 + 7;//XXX
const int C = 26;//XXX
 
void add(int &x, int y){
	x += y;
	while (x >= MOD) x -= MOD;
	while (x < 0) x += MOD;
}
 
int fix(int x){
	while (x >= MOD) x -= MOD;
	while (x < 0) x += MOD;
	return x;
}
 
int pw(int a, int b){
	int ret = 1;
	while (b){
		if (b & 1)
			ret = 1ll*ret*a%MOD;
		b >>= 1;
		a = 1ll*a*a%MOD;
	}
	return ret;
}
 
const int MAXN = 1505;

int n, m, sec[MAXN];
vector<int> a[MAXN], b[MAXN];

map<vector<int>, vector<int>> mp;

void die() { cout << "-1\n"; exit(0); }

int qu[MAXN], h, t;
int wrong[MAXN], done[MAXN];

void solve() {
	cin >> n >> m;

	for(int i = 0; i < n; i++) {
		a[i].resize(m);
		for(int &x : a[i])
			cin >> x;
	}

	for(int i = 0; i < n; i++) {
		b[i].resize(m);
		for(int &x : b[i])
			cin >> x;
	}
	for(int j = 0; j < m; j++) {
		for(int i = 0; i < n-1; i++) {
			if(b[i][j] > b[i+1][j]) {
				++wrong[j];
			}
		}
		if(wrong[j] == 0)
			qu[t++] = j;
	}
	
	while(t-h) {
		int col = qu[h++];
		for(int row = 0; row < n-1; row++) {
			if(!done[row] && b[row][col] < b[row+1][col]) {
				// this row was moved here
				// so lets remove all times where he was > than row below him
				done[row] = 1;
				for(int col2 = 0; col2 < m; col2++) {
					if(b[row][col2] > b[row+1][col2]) {
						if(--wrong[col2] == 0) {
							qu[t++] = col2;
						}
					}
				}
			}
		}
	}
	reverse(qu, qu+t);
	iota(sec, sec+n, 0);
	for(int i = 0; i < t; i++) {
		stable_sort(sec, sec+n, [&](int x, int y) {
			return a[x][qu[i]] < a[y][qu[i]];
		});
	}
	for(int i = 0; i < n; i++) {
		if(a[sec[i]] != b[i]) {
			die();
		}
	}
	
	cout << t << "\n";
	for(int i = 0; i < t; i++)
		cout << qu[i]+1 << " ";
	cout << "\n";
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//cout << fixed << setprecision(6);
	
	int te = 1;	
	//cin >> te;
	for (int w = 1; w <= te; w++){
		//cout << "Case #" << w << ": ";
		solve();
	}
	return 0;
}
