#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > ans;
vector<vector<int> > file;
vector<int> closter;
void move(int from, int to) {
  if (from == to) return;
  for (int i = 0; i < (int)(file[closter[from]]).size(); i++) {
    if (file[closter[from]][i] == from) {
      file[closter[from]][i] = to;
      swap(closter[from], closter[to]);
      ans.push_back(make_pair(from + 1, to + 1));
      break;
    }
  }
}
void go_swap(int now, int next) {
  int inter;
  for (int i = 0; i < (int)(closter).size(); i++) {
    if (closter[i] == -1) {
      inter = i;
      break;
    }
  }
  move(next, inter);
  move(now, next);
}
int main() {
  int n_closter, n_file;
  cin >> n_closter >> n_file;
  file = vector<vector<int> >(n_file);
  closter = vector<int>(n_closter, -1);
  int n;
  for (int i = 0; i < n_file; i++) {
    cin >> n;
    file[i].resize(n);
    for (int j = 0; j < n; j++) {
      cin >> file[i][j];
      file[i][j]--;
      closter[file[i][j]] = i;
    }
  }
  int k = 0;
  for (int i = 0; i < n_file; i++) {
    for (int j = 0; j < (int)(file[i]).size(); j++) {
      if (file[i][j] != k) go_swap(file[i][j], k);
      k++;
    }
  }
  cout << (int)(ans).size() << endl;
  for (int i = 0; i < (int)(ans).size(); i++) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}
