#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, seq = 0, x, y, j = 0, z = 0;
  vector<pair<int, int> > res;
  cin >> n >> m;
  int a[n + 1];
  memset(a, 0, sizeof a);
  for (int i = 0; i < m; i++) {
    cin >> x;
    for (j = x; j > 0; j--) {
      cin >> y;
      a[y] = ++seq;
    }
  }
  for (z = 1; z <= n; z++) {
    if (a[z] == 0) break;
  }
  for (int i = 1; i <= seq; i++) {
    if (a[i] != i) {
      for (j = i + 1; j <= n; j++) {
        if (a[j] == i) break;
      }
      if (i != z) res.push_back(make_pair(i, z));
      res.push_back(make_pair(j, i));
      a[z] = a[i];
      a[i] = i;
      z = j;
    }
  }
  cout << res.size() << endl;
  for (int i = 0; i < res.size(); i++)
    cout << res[i].first << " " << res[i].second << endl;
  return 0;
}
