#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back

void die(ll x)
{
    cout<<x<<flush;
    exit(0);
}

const ll mod=1000000009;
ll p=31;
ll ppow[1501];

int n,m;
ll a[1501][1501];
ll b[1501][1501];
multimap<vector<int>,int> hash_b;
int where_in_a[1501];
vector<int> positive[1501];
int negative[1501];
vector<int> negatives[1501];
vector<int> solution;
vector<int> a_rows[1501];

int main()
{
    ios_base::sync_with_stdio(false);
    //freopen("Codeforces Round #707 (Div. 1, based on Moscow Open Olympiad in Informatics) C.txt","r",stdin);
    cin>>n>>m;
    ppow[0]=1;
    for(ll i=1;i<=m;i++) ppow[i]=(ppow[i-1]*p)%mod;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>a[i][j];
            a_rows[i].push_back(a[i][j]);
        }
    }
    for(int i=1;i<=n;i++)
    {
        vector<int> curr;
        for(int j=1;j<=m;j++)
        {
            cin>>b[i][j];
            curr.push_back(b[i][j]);
        }
        hash_b.insert({curr,i});
    }
    for(int i=1;i<=n;i++)
    {
        auto it=hash_b.find(a_rows[i]);
        if(it==hash_b.end()) die(-1);
        where_in_a[(*it).second]=i;
        hash_b.erase(it);
    }
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[where_in_a[i]][j]==a[where_in_a[i+1]][j]) continue;
            if(a[where_in_a[i]][j]<a[where_in_a[i+1]][j]) positive[j].push_back(i);
            else
            {
                negative[j]++;
                negatives[i].push_back(j);
            }
        }
    }
    queue<int> todo;
    for(int i=1;i<=m;i++)
    {
        if(!negative[i]) todo.push(i);
    }
    while(!todo.empty())
    {
        int col=todo.front();
        todo.pop();
        solution.push_back(col);
        for(auto s:positive[col])
        {
            if(!negatives[s].empty())
            {
                for(auto c:negatives[s])
                {
                    negative[c]--;
                    if(!negative[c]) todo.push(c);
                }
                negatives[s].clear();
            }
        }
    }
    for(int i=1;i<n;i++)
    {
        if(!negatives[i].empty()) die(-1);
    }
    cout<<solution.size()<<endl;
    while(!solution.empty())
    {
        cout<<solution.back()<<" ";
        solution.pop_back();
    }
    cout<<flush;
    return 0;
}
