#include <bits/stdc++.h>
using namespace std;
const int M = 1000 + 5;
pair<int, int> a[M];
pair<int, int> ans[M];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int ni;
    cin >> ni;
    for (int j = 0; j < ni; j++) {
      int id;
      cin >> id;
      a[id] = make_pair(i, j + 1);
    }
  }
  int freeid = -1;
  for (int i = 1; i <= n; i++) {
    if (a[i].first == 0) {
      freeid = i;
      break;
    }
  }
  int num = 0;
  for (int i = 1; i <= n; i++) {
    int minv = M;
    int minid = -1;
    for (int j = i; j <= n; j++) {
      if (a[j].first > 0) {
        if (a[j].first < minv) {
          minv = a[j].first;
          minid = j;
        } else {
          if (a[j].first == minv) {
            if (a[j].second < a[minid].second) {
              minid = j;
            }
          }
        }
      }
    }
    if (minid == -1) {
      break;
    } else {
      if (a[i].first == 0) {
        ans[num++] = make_pair(minid, i);
        pair<int, int> tmp = a[i];
        a[i] = a[minid];
        a[minid] = tmp;
        freeid = minid;
      } else {
        if (a[i] != a[minid]) {
          ans[num++] = make_pair(i, freeid);
          ans[num++] = make_pair(minid, i);
          pair<int, int> tmp = a[i];
          a[i] = a[freeid];
          a[freeid] = tmp;
          tmp = a[minid];
          a[minid] = a[i];
          a[i] = tmp;
          freeid = minid;
        }
      }
    }
  }
  cout << num << endl;
  for (int i = 0; i < num; i++) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}
