#include <bits/stdc++.h>
using namespace std;
int a[210][210], use[210], num[210];
int x[410], y[410];
int in[210], from[210];
int main() {
  int m, n;
  while (scanf("%d%d", &m, &n) == 2) {
    int tnow = 0;
    memset(use, 0, sizeof(use));
    for (int i = 0; i < n; i++) {
      scanf("%d", &num[i]);
      for (int j = 0; j < num[i]; j++) {
        tnow++;
        scanf("%d", &a[i][j]);
        in[a[i][j]] = tnow;
        from[tnow] = a[i][j];
        use[a[i][j]] = 1;
      }
    }
    int space;
    for (int i = 1; i <= m; i++)
      if (!use[i]) space = i;
    int cnt = 0, now = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < num[i]; j++) {
        now++;
        if (from[now] == now) continue;
        if (!in[now]) {
          x[cnt] = from[now];
          y[cnt++] = now;
          in[from[now]] = 0;
          if (now == space) space = from[now];
          from[now] = now;
          in[now] = now;
        } else {
          x[cnt] = now;
          y[cnt++] = space;
          in[space] = in[now];
          from[in[now]] = space;
          x[cnt] = from[now];
          y[cnt++] = now;
          in[from[now]] = 0;
          space = from[now];
          in[now] = now;
          from[now] = now;
        }
      }
    }
    printf("%d\n", cnt);
    for (int i = 0; i < cnt; i++) printf("%d %d\n", x[i], y[i]);
  }
  return 0;
}
