#include <bits/stdc++.h>
using namespace std;
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
vector<pair<int, int> > fi, ops;
vector<vector<int> > loc;
void move(int i, int j) {
  if (i == j) return;
  fi[j] = fi[i];
  fi[i] = pair<int, int>(-1, 0);
  loc[fi[j].first][fi[j].second] = j;
  ops.emplace_back(i + 1, j + 1);
}
int main() {
  int n, m;
  cin >> n >> m;
  fi.assign(n, {-1, 0});
  loc.resize(m);
  for (int c = 0; c < m; c++) {
    int i, j;
    cin >> i;
    for (int d = 0; d < i; d++) {
      cin >> j;
      j--;
      loc[c].push_back(j);
      fi[j] = pair<int, int>(c, d);
    }
  }
  for (int c = 0, i = 0; c < m; c++)
    for (int d = 0; d < loc[c].size(); d++, i++) {
      if (fi[i].first != -1) {
        int j =
            fi.rend() - find(fi.rbegin(), fi.rend(), pair<int, int>{-1, 0}) - 1;
        move(i, j);
      }
      move(loc[c][d], i);
    }
  cout << ops.size() << endl;
  for (int c = 0; c < ops.size(); c++)
    cout << ops[c].first << ' ' << ops[c].second << endl;
  return 0;
}
