#include <bits/stdc++.h>
using namespace std;
int n, m, sum, ans;
int final[1010][2];
int s[1010][1010], t[1010][1010];
int cnt[1010];
struct cong {
  int x, y;
  cong() {}
  cong(int a, int b) {
    x = a;
    y = b;
  }
  bool operator<(const cong& a) const {
    if (x == a.x) return y < a.y;
    return x < a.x;
  }
};
map<int, cong> local, ord;
int getsmallest() {
  int hehe = 0;
  for (int i = 1; i <= n; i++) {
    cong tmp = local[i];
    if (tmp.x == -1 && tmp.y == -1) {
      hehe = i;
      break;
    }
  }
  return hehe;
}
bool ok(int k) {
  if (k > sum) return false;
  return true;
}
void swapp(int inchange, int k) {
  ans++;
  final[ans][0] = inchange;
  final[ans][1] = k;
  cong tmp = local[inchange];
  local[k] = local[inchange];
  s[tmp.x][tmp.y] = k;
  local[inchange] = cong(-1, -1);
  tmp = local[inchange];
}
void solve() {
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= cnt[i]; j++) {
      if (s[i][j] != t[i][j]) {
        cong tmp = local[t[i][j]];
        if (tmp.x == -1 && tmp.y == -1) {
          swapp(s[i][j], t[i][j]);
          s[i][j] = t[i][j];
        } else {
          int k = getsmallest();
          int inchange = s[i][j];
          int nowi = i;
          int nowj = j;
          do {
            swapp(inchange, k);
            s[nowi][nowj] = k;
            swap(inchange, k);
            if (!ok(k)) break;
            cong temp = ord[k];
            inchange = s[temp.x][temp.y];
            nowi = temp.x;
            nowj = temp.y;
          } while (true);
        }
      }
    }
}
int main() {
  scanf("%d%d", &n, &m);
  if (true) {
    sum = 0;
    ans = 0;
    for (int i = 1; i <= n; i++) {
      local[i] = cong(-1, -1);
      ord[i] = cong(-1, -1);
    }
    for (int i = 1; i <= m; i++) {
      scanf("%d", &cnt[i]);
      for (int j = 1; j <= cnt[i]; j++) {
        scanf("%d", &s[i][j]);
        local[s[i][j]] = cong(i, j);
        t[i][j] = ++sum;
        ord[sum] = cong(i, j);
      }
    }
    solve();
    printf("%d\n", ans);
    for (int i = 1; i <= ans; i++) {
      printf("%d %d\n", final[i][0], final[i][1]);
    }
  }
  return 0;
}
