#include <bits/stdc++.h>
using namespace std;
set<int> emptys;
vector<int> files[260];
pair<int, int> sectors[260];
vector<pair<int, int> > res;
void move(int from, int to) {
  res.push_back(make_pair(from, to));
  emptys.insert(from);
  emptys.erase(to);
  files[sectors[from].first][sectors[from].second - 1] = to;
  sectors[to] = sectors[from];
}
int main() {
  int np, nf;
  cin >> np >> nf;
  for (int i = 1; i <= np; i++) {
    emptys.insert(i);
  }
  for (int i = 1; i <= nf; i++) {
    int ns;
    cin >> ns;
    for (int j = 1; j <= ns; j++) {
      int sec;
      cin >> sec;
      emptys.erase(sec);
      files[i].push_back(sec);
      sectors[sec] = make_pair(i, j);
    }
  }
  int c = 1;
  for (int i = 1; i <= nf; i++) {
    for (int j = 0; j < files[i].size(); j++) {
      if (files[i][j] == c) {
        c++;
        continue;
      }
      if (emptys.find(c) == emptys.end()) {
        move(c, *emptys.begin());
      }
      move(files[i][j], c);
      c++;
    }
  }
  cout << res.size() << endl;
  for (int i = 0; i < res.size(); i++) {
    cout << res[i].first << " " << res[i].second << endl;
  }
  return 0;
}
