#include <bits/stdc++.h>
struct fun {
  int x, y;
} b[505] = {0};
int main() {
  int a[202], n, m, i, count, t, r, j, k;
  while (scanf("%d%d", &n, &m) != EOF) {
    count = 0;
    memset(a, 0, sizeof(a));
    for (i = 0; i < m; i++) {
      scanf("%d", &t);
      for (j = 0; j < t; j++) {
        scanf("%d", &r);
        a[r] = ++count;
      }
    }
    t = 0;
    for (i = 1; i <= count; i++) {
      if (a[i] == i) continue;
      for (j = i + 1;; j++)
        if (a[j] == i) break;
      for (k = i;; k++)
        if (a[k] == 0) break;
      if (k == i) {
        a[i] = a[j];
        b[++t].x = j;
        b[t].y = i;
        a[j] = 0;
      } else {
        a[k] = a[i];
        b[++t].x = i;
        b[t].y = k;
        a[i] = a[j];
        b[++t].x = j;
        b[t].y = i;
        a[j] = 0;
      }
    }
    printf("%d\n", t);
    for (i = 1; i <= t; i++) printf("%d %d\n", b[i].x, b[i].y);
  }
}
