#include <bits/stdc++.h>
using namespace std;
long long a[500], b[500], c[500];
struct as {
  long long x, y;
} res[500];
int main() {
  long long n, m, f = 1;
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= m; i++) {
    long long q;
    scanf("%lld", &q);
    for (long long j = 1; j <= q; j++) {
      long long x;
      scanf("%lld", &x);
      a[x] = i;
      c[x] = f;
      b[f++] = x;
    }
  }
  long long pos = 0;
  for (long long i = 1; i <= n; i++) {
    if (a[i] == 0) {
      pos = i;
      break;
    }
  }
  long long g = 1;
  for (long long i = 1; i < f; i++) {
    if (i == b[i]) continue;
    if (a[i] == 0) {
      res[g].x = b[i];
      res[g].y = i;
      g++;
      a[i] = a[b[i]];
      a[b[i]] = 0;
      pos = b[i];
    } else {
      res[g].x = i;
      res[g].y = pos;
      g++;
      res[g].x = b[i];
      res[g].y = i;
      g++;
      a[pos] = a[i];
      b[c[i]] = pos;
      c[pos] = c[i];
      a[i] = a[b[i]];
      a[b[i]] = 0;
      pos = b[i];
    }
  }
  printf("%lld\n", g - 1);
  for (long long i = 1; i < g; i++) {
    printf("%lld %lld\n", res[i].x, res[i].y);
  }
  return 0;
}
