#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[300], ans[500][2], tot, v[300];
void sl(int p, int x) {
  if (p == x || x == 0) return;
  if (a[x] == 0 || a[x] == x) {
    ans[tot][0] = p, ans[tot][1] = x;
    a[x] = x;
    a[p] = 0;
    tot++;
    return;
  }
  if (v[x]) {
    ans[tot][0] = p, ans[tot][1] = n;
    a[p] = 0;
    a[n] = x;
    tot++;
    return;
  }
  v[p] = 1;
  sl(x, a[x]);
  ans[tot][0] = p, ans[tot][1] = x;
  a[x] = x;
  a[p] = 0;
  tot++;
  v[p] = 0;
}
int main() {
  scanf("%d%d", &n, &m);
  int p = 0, t, sum = 0;
  for (int i = 0; i < m; i++) {
    scanf("%d", &t);
    sum += t;
    while (t--) {
      int x;
      scanf("%d", &x);
      a[x] = ++p;
    }
  }
  for (int i = n; i > 0; i--) {
    sl(i, a[i]);
    sl(n, a[n]);
  }
  printf("%d\n", tot);
  for (int i = 0; i < tot; i++) {
    printf("%d %d\n", ans[i][0], ans[i][1]);
  }
}
