#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define D if(0)

using namespace std;

using ll = long long;

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

  int n, m; cin >> n >> m;

  map<vector<int>, queue<int>> a;
  for(int i = 0; i < n; i++) {
    vector<int> b(m);
    for(int j = 0; j < m; j++)
      cin >> b[j];
    a[b].push(i);
  }

  vector<vector<int> > b(n, vector<int>(m));
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++) {
      cin >> b[i][j];
    }

    auto& q = a[b[i]];
    if(q.empty()) {
      cout << "-1\n";
      return 0;
    }

    b[i].push_back(q.front());
    q.pop();
  }

  vector<vector<int> > r(n);
  vector<vector<int> > g(m+1);
  vector<int> d(m+1, 0);
  for(int i = 1; i < n; i++) {
    for(int j = 0; j < m+1; j++) {
      if(b[i][j] > b[i-1][j]) {
        g[j].push_back(i);
      } else if(b[i][j] < b[i-1][j]) {
        r[i].push_back(j);
        d[j]++;
      }
    }
  }

  vector<int> ans;
  queue<int> q;

  for (int i = 0; i < m + 1; i++)
    if (d[i] == 0)
      q.push(i);

  while(!q.empty()) {
    int col = q.front(); q.pop();

    if(col == m) {
      ans.push_back(col);
      break;
    }

    int aff = 0;
    for(int row: g[col]) {
      aff += r[row].size();
      for(int ocol: r[row]) {
        if(--d[ocol] == 0) {
          q.push(ocol);
        }
      }
      r[row].clear();
    }

    if(aff) ans.push_back(col);
  }

  if(ans.empty() || ans.back() != m) {
    cout << "-1\n";
    return 0;
  }

  ans.pop_back();
  reverse(all(ans));

  cout << ans.size() << "\n";
  for(int i = 0; i < ans.size(); i++) {
    if(i) cout << " ";
    cout << ans[i]+1;
  } cout << "\n";

  return 0;
}
