#include <bits/stdc++.h>
using namespace std;
int len, fileNum, cl, staloc, n;
int des[205], mov[405][2];
int main() {
  staloc = 0;
  memset(des, -1, sizeof(des));
  scanf("%d%d", &len, &fileNum);
  for (int i = 0; i < fileNum; i++) {
    scanf("%d", &n);
    for (int j = 0; j < n; j++) {
      scanf("%d", &cl);
      des[cl - 1] = staloc + j;
    }
    staloc += n;
  }
  n = staloc;
  int ii = 0, mk = 0, space;
  while (des[ii] != -1) ii++;
  space = ii;
  for (int i = 0; i < n; i++) {
    if (des[i] != i) {
      if (des[i] != -1) {
        mov[mk][0] = i;
        mov[mk++][1] = space;
        des[space] = des[i];
        des[i] = -1;
      }
      for (int j = i + 1; j < len; j++) {
        if (des[j] == i) {
          mov[mk][0] = j;
          mov[mk++][1] = i;
          des[i] = i;
          des[j] = -1;
          space = j;
          break;
        }
      }
    }
  }
  printf("%d\n", mk);
  for (int i = 0; i < mk; i++) printf("%d %d\n", mov[i][0] + 1, mov[i][1] + 1);
  return 0;
}
