#include <bits/stdc++.h>
using namespace std;
int fileNo[222];
int even[222];
int op[222 * 2][2], on;
int posn[222];
int sf, n, m;
int main() {
  int i, j, k;
  scanf("%d%d", &n, &m);
  memset(fileNo, 0, sizeof(fileNo));
  sf = 0;
  for (i = 1; i <= m; i++) {
    scanf("%d", &even[i]);
    for (j = 1; j <= even[i]; j++) {
      scanf("%d", &k);
      fileNo[k] = ++sf;
    }
  }
  on = 0;
  int pa, pb;
  for (i = 1; i <= sf; i++) {
    for (pa = i; pa <= n && fileNo[pa] != i; pa++)
      ;
    if (pa == i) continue;
    for (pb = i; pb <= n && fileNo[pb] != 0; pb++)
      ;
    if (i != pb) {
      ++on;
      op[on][0] = i;
      op[on][1] = pb;
    }
    if (pa != i) {
      ++on;
      op[on][0] = pa;
      op[on][1] = i;
    }
    fileNo[pb] = fileNo[i];
    fileNo[i] = fileNo[pa];
    fileNo[pa] = 0;
  }
  printf("%d\n", on);
  for (i = 1; i <= on; i++) printf("%d %d\n", op[i][0], op[i][1]);
  return 0;
}
