#include <bits/stdc++.h>
using namespace std;
bool used[210];
int ans[410][2];
int main() {
  int N, K;
  scanf("%d%d", &N, &K);
  fill(used, used + N + 1, false);
  vector<int> iv_s, iv_d;
  int pos, num, cur = 1;
  for (int i = 1; i <= K; i++) {
    scanf("%d", &num);
    for (int j = 1; j <= num; j++) {
      scanf("%d", &pos);
      if (pos != cur) {
        iv_s.push_back(pos);
        iv_d.push_back(cur);
      }
      used[pos] = true;
      cur++;
    }
  }
  int step = 0;
  while (iv_s.size() > 0) {
    bool ok = false;
    for (int i = 0; i < iv_s.size(); i++) {
      if (used[iv_d[i]] == false) {
        ans[step][0] = iv_s[i];
        ans[step++][1] = iv_d[i];
        used[iv_d[i]] = true;
        used[iv_s[i]] = false;
        ok = true;
        iv_d.erase(iv_d.begin() + i);
        iv_s.erase(iv_s.begin() + i);
      }
    }
    if (ok == false) {
      for (int i = 1; i <= N; i++) {
        if (!used[i]) {
          ans[step][0] = iv_s[0];
          ans[step++][1] = i;
          used[iv_s[0]] = false;
          iv_s[0] = i;
          used[i] = true;
          break;
        }
      }
    }
  }
  printf("%d\n", step);
  for (int i = 0; i < step; i++) printf("%d %d\n", ans[i][0], ans[i][1]);
  return 0;
}
