#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > cl(n, pair<int, int>(-1, -1));
  for (int i = 0; i < m; i++) {
    int l;
    cin >> l;
    for (int j = 0; j < l; j++) {
      int x;
      cin >> x;
      cl[x - 1].first = i;
      cl[x - 1].second = j;
    }
  }
  int free;
  for (int i = 0; i < n; i++) {
    if (cl[i].first == -1) {
      free = i;
      break;
    }
  }
  vector<pair<int, int> > sol;
  int z = 0;
  for (int i = 0; i < n; i++) {
    if (cl[i].second == 0) {
      if (i != z) {
        swap(cl[z], cl[free]);
        swap(cl[i], cl[z]);
        if (z != free) sol.push_back(pair<int, int>(z + 1, free + 1));
        free = i;
        sol.push_back(pair<int, int>(i + 1, z + 1));
      }
      z++;
      for (int j = z; j < n; j++) {
        if (cl[z - 1].first == cl[j].first &&
            cl[z - 1].second + 1 == cl[j].second) {
          if (j != z) {
            swap(cl[z], cl[free]);
            swap(cl[j], cl[z]);
            if (z != free) sol.push_back(pair<int, int>(z + 1, free + 1));
            free = j;
            sol.push_back(pair<int, int>(j + 1, z + 1));
          }
          j = z;
          z++;
        }
      }
      i = z - 1;
    }
  }
  cout << sol.size() << endl;
  for (int i = 0; i < sol.size(); i++)
    cout << sol[i].first << " " << sol[i].second << endl;
  return 0;
}
