#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include <map>
#include <cassert>
#include <time.h>
#include <chrono>
#include <random>
#include <set>
#include <queue>
#include <sstream>
 
using namespace std;
 
typedef long long int ll;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef pair <int, int> ii;
typedef vector <ii> vii;

vvi V; // n x (m+1)
vvi sum, intervals;
vi ans, taken, inco;
int n, m;

void compute(){
    sum = vvi(n, vi(m+1, 0));

    for (int i = 1; i < n; ++i){
        for (int j = 0; j <= m; ++j){
            sum[i][j] = sum[i-1][j];

            if (V[i][j] < V[i-1][j]) ++sum[i][j];
        }
    }
}

int amount(int col, int l, int r){
    if (sum[r][col] - sum[l][col]) return 1;
    return 0;
}

void updatepos(int l, int r){
    for (int i = 0; i <= m; ++i) inco[i] += amount(i, l, r);
}

void updateneg(int l, int r){
    for (int i = 0; i <= m; ++i) inco[i] -= amount(i, l, r);
}

bool findnext(){
    //cout << " !!! NEW ROUND " << intervals.size() << " therefore " << intervals.empty() << endl;
    if (intervals.empty()) return true;
    
    for (int i = 0; i <= m; ++i){
        if (not taken[i] and not inco[i]) {
            //cout << " GO FOR COLUMN " << i << endl;

            ans.push_back(i);
            taken[i] = 1;

            vvi newintervals;

            for (int k = 0; k < intervals.size(); ++k){
                int l = intervals[k][0], r = intervals[k][1];

                int last = l;
                for (int t = l + 1; t <= r; ++t){
                    if (V[t][i] == V[last][i]) continue;

                    //cout << last << " and " << t << endl;

                    if (t - last > 1){
                        newintervals.push_back({last, t-1});
                        updatepos(last, t-1);
                    }

                    last = t;
                }

                //cout << "with interval " << k << " --> " << last << endl;
                if (last == l) newintervals.push_back(intervals[k]);
                else {
                    updateneg(l, r);

                    if (r - last > 0){
                        newintervals.push_back({last, r});
                        updatepos(last, r);
                    }
                }
            }

            intervals = newintervals;
            return findnext();
        }
    }

    return false;
}

bool solve(){
    compute();
    intervals = {{0, n-1}};
    inco = vi(m+1, 0);
    taken = vi(m+1, 0);

    for (int i = 0; i <= m; ++i) inco[i] += amount(i, 0, n-1);

    /*cout << "WHY" << endl;
    for (int i = 0; i <= m; ++i) cout << inco[i] << ' ';
    cout << endl;*/

    return findnext();
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;
    V = vvi(n);

    map <vi, queue <int> > M;

    for (int i = 0; i < n; ++i){
        vi temp(m);
        for (int j = 0; j < m; ++j) cin >> temp[j];
        M[temp].push(i);
    }   

    bool possible = true;

    for (int i = 0; i < n; ++i){
        vi temp(m);
        for (int j = 0; j < m; ++j) cin >> temp[j];

        queue <int>& aux = M[temp];
        if (aux.empty()) possible = false;
        else {
            int x = aux.front(); aux.pop();
            temp.push_back(x);
            V[i] = temp;
        }
    }

    /*cout << " SEE *** " << endl;
    for (int i = 0; i < n; ++i){
        for (int j = 0; j <= m; ++j) cout << V[i][j] << ' ';
        cout << endl;
    }   
    cout << " ^^^^^ " << endl; */
    

    if (not possible) cout << -1 << endl;
    else {
        possible = solve();
        if (not possible) cout << -1 << endl;
        else {
            //cout << " HERE WE ARE " << ans.size() << endl;

            vi trueans;

            for (int i = int(ans.size()) - 1; i >= 0; --i){
                if (ans[i] < m) trueans.push_back(ans[i] + 1);
            }

            cout << trueans.size() << endl;
            for (int i = 0; i < trueans.size(); ++i) cout << trueans[i] << ' ';
            cout << endl;
        }
    }
}
