#include <bits/stdc++.h>
using namespace std;
int a[205][205];
int file[205];
int frag[205];
bool mark[205];
vector<int> ans1, ans2;
void Put(int mabda, int maghsad, int &empty) {
  if (maghsad != empty) {
    ans1.push_back(maghsad);
    ans2.push_back(empty);
    file[empty] = file[maghsad];
    frag[empty] = frag[maghsad];
    if (frag[empty] != 0) a[file[empty]][frag[empty]] = empty;
  }
  ans1.push_back(mabda);
  ans2.push_back(maghsad);
  file[maghsad] = file[mabda];
  frag[maghsad] = frag[mabda];
  a[file[maghsad]][frag[maghsad]] = maghsad;
  empty = mabda;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i][0];
    for (int j = 1; j <= a[i][0]; j++) {
      cin >> a[i][j];
      mark[a[i][j]] = true;
      file[a[i][j]] = i;
      frag[a[i][j]] = j;
    }
  }
  int empty;
  int p = 1;
  for (int i = 1; i <= n; i++)
    if (!mark[i]) {
      empty = i;
      break;
    }
  for (int i = 0; i < m; i++) {
    for (int j = 1; j <= a[i][0]; j++) {
      if (file[p] != i || frag[p] != j) Put(a[i][j], p, empty);
      p++;
    }
  }
  cout << ans1.size() << endl;
  for (int i = 0; i < ans1.size(); i++)
    cout << ans1[i] << ' ' << ans2[i] << endl;
  return 0;
}
