#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
vector<int> st[222];
int w[222], ww[222];
int main() {
  int n, m;
  cin >> n >> m;
  int it = 1;
  for (int i = 1; i <= m; i++) {
    int x;
    cin >> x;
    for (int j = 0; j < x; j++) {
      int y;
      cin >> y;
      w[it] = y;
      ww[y] = it;
      it++;
    }
  }
  vector<pair<int, int> > res;
  for (int i = 1; i < it; i++) {
    if (w[i] == i) continue;
    if (ww[i] == 0) {
      res.push_back(make_pair(w[i], i));
      ww[w[i]] = 0;
      w[i] = i;
      ww[i] = i;
    } else {
      int empty = -1;
      for (int j = 1; j <= n; j++) {
        if (ww[j] == 0) {
          empty = j;
        }
      }
      res.push_back(make_pair(i, empty));
      w[ww[i]] = empty;
      ww[empty] = ww[i];
      ww[i] = 0;
      res.push_back(make_pair(w[i], i));
      ww[w[i]] = 0;
      w[i] = i;
      ww[i] = i;
    }
  }
  cout << (int)(res).size() << endl;
  for (int i = 0; i < (int)(res).size(); i++) {
    cout << res[i].first << " " << res[i].second << endl;
  }
  return 0;
}
