#include <bits/stdc++.h>
int b[1000], pre[1000], nxt[1000], ansx[1000], ansy[1000], head[1000], n, m, k,
    blk, la, t;
void move(int x) {
  ansx[++la] = x, ansy[la] = blk;
  if (x == head[b[x]]) {
    head[b[x]] = blk;
    pre[nxt[x]] = blk;
    pre[blk] = 0;
    nxt[blk] = nxt[x];
    b[blk] = b[x];
    pre[x] = nxt[x] = b[x] = 0;
  } else if (nxt[x] == 0) {
    nxt[pre[x]] = blk;
    pre[blk] = pre[x];
    b[blk] = b[x];
    pre[x] = nxt[x] = b[x] = 0;
  } else {
    nxt[pre[x]] = blk;
    pre[nxt[x]] = blk;
    nxt[blk] = nxt[x];
    pre[blk] = pre[x];
    b[blk] = b[x];
    pre[x] = nxt[x] = b[x] = 0;
  }
  blk = x;
}
int solve(int x, int y) {
  if (x != y) {
    if (y != blk) move(y);
    move(x);
  }
  return y;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d", &k);
    int p;
    scanf("%d", &p);
    b[head[i] = p] = i;
    for (int j = 2; j <= k; ++j) {
      scanf("%d", &nxt[p]);
      pre[nxt[p]] = p;
      p = nxt[p];
      b[p] = i;
    }
  }
  for (blk = 1; b[blk]; ++blk)
    ;
  for (int i = 1; i <= m; ++i) {
    int p = head[i];
    ++t;
    p = solve(p, t);
    while (nxt[p]) {
      p = nxt[p];
      ++t;
      p = solve(p, t);
    }
  }
  printf("%d\n", la);
  for (int i = 1; i <= la; ++i) printf("%d %d\n", ansx[i], ansy[i]);
  return 0;
}
