#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
int aabs(int a) {
  if (a < 0) return -a;
  return a;
}
int gcd(int a, int b) {
  while (a > 0 && b > 0) {
    if (a > b) {
      a %= b;
    } else {
      b %= a;
    }
  }
  return a + b;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> g[213];
  int a[213];
  memset(a, 255, sizeof(a));
  int sv;
  for (int i = 0; i < m; i++) {
    int t;
    cin >> t;
    for (int j = 0; j < t; j++) {
      int tt;
      cin >> tt;
      tt--;
      g[i].push_back(tt);
      a[tt] = i;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] < 0) sv = i;
  }
  vector<pair<int, int> > ans;
  int last = 0;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < g[i].size(); j++) {
      if (g[i][j] == last) {
        last++;
        continue;
      }
      if (a[last] < 0) {
        ans.push_back(make_pair(g[i][j], last));
        sv = g[i][j];
        g[i][j] = last;
        a[last] = i;
        a[sv] = -1;
        last++;
      } else {
        int mm = a[last];
        for (int k = 0; k < g[mm].size(); k++) {
          if (g[mm][k] == last) {
            ans.push_back(make_pair(g[mm][k], sv));
            g[mm][k] = sv;
            sv = last;
            a[last] = -1;
            a[g[mm][k]] = mm;
            ans.push_back(make_pair(g[i][j], last));
            sv = g[i][j];
            g[i][j] = last;
            a[last] = i;
            a[sv] = -1;
            last++;
            break;
          }
        }
      }
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i].first + 1 << ' ' << ans[i].second + 1 << endl;
  }
  return 0;
}
