#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int> > V;
  vector<int> used(n + 1);
  map<int, pair<int, int> > M;
  for (int i = 0; i < m; ++i) {
    int nn;
    cin >> nn;
    vector<int> v(nn);
    for (int j = 0; j < nn; ++j) {
      cin >> v[j];
      used[v[j]] = 1;
      M[v[j]] = make_pair(i, j);
    }
    V.push_back(v);
  }
  int x = 0;
  for (int i = 1; i <= n; ++i) {
    if (!used[i]) {
      x = i;
      break;
    }
  }
  vector<pair<int, int> > res;
  int cnt = 1;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < V[i].size(); ++j) {
      if (V[i][j] == cnt) {
        ++cnt;
        continue;
      }
      if (cnt != x) {
        res.push_back(make_pair(cnt, x));
        if (M.count(cnt)) {
          pair<int, int> p = M[cnt];
          V[p.first][p.second] = x;
          M[x] = p;
        }
      }
      res.push_back(make_pair(V[i][j], cnt));
      x = V[i][j];
      ++cnt;
    }
  }
  cout << res.size() << endl;
  for (int i = 0; i < res.size(); ++i) {
    cout << res[i].first << " " << res[i].second << endl;
  }
  return 0;
}
