#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
struct cluster {
  int file, num;
};
int main() {
  int n, m, i, j, k, cp, cc = 0, fs[1000];
  cluster a[1000];
  vector<pair<int, int> > ans;
  cin >> n >> m;
  for (i = 0; i < n; i++) a[i].file = -1;
  for (i = 0; i < m; i++) {
    cin >> fs[i];
    cc += fs[i];
    for (j = 0; j < fs[i]; j++) {
      cin >> cp;
      a[--cp].file = i;
      a[cp].num = j;
    }
  }
  int cf = cp = 0;
  i = 0;
  while (i < cc) {
    int from, to;
    if (a[i].file == -1) goto nx;
    from = i;
    to = i + 1;
    while (a[to].file != -1) to++;
    a[to] = a[from];
    a[from].file = -1;
    ans.push_back(make_pair(from, to));
  nx:
    to = i;
    from = i + 1;
    while (a[from].file != cf || a[from].num != cp) from++;
    a[to] = a[from];
    a[from].file = -1;
    ans.push_back(make_pair(from, to));
    if (cp == fs[cf] - 1)
      cf++, cp = 0;
    else
      cp++;
    i++;
  }
  cout << ans.size() << endl;
  for (i = 0; i < ans.size(); i++)
    cout << ans[i].first + 1 << ' ' << ans[i].second + 1 << endl;
  return 0;
}
