#include <bits/stdc++.h>
using namespace std;
int a[205][205], n, m, c[2005], d[20005];
map<int, pair<int, int> > p;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> c[i];
    for (int j = 1; j <= c[i]; j++) {
      cin >> a[i][j];
      d[a[i][j]]++;
      p[a[i][j]] = {i, j};
    }
  }
  int k = 0;
  for (int i = 1; i <= n; i++) {
    if (!d[i]) {
      k = i;
      break;
    }
  }
  int now = 1;
  vector<pair<int, int> > op;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= c[i]; j++) {
      if (a[i][j] == now) {
        now++;
        continue;
      } else {
        if (k == now) {
          op.push_back({a[i][j], now});
          k = a[i][j];
          p[a[i][j]] = {0, 0};
        } else {
          op.push_back({now, k});
          a[p[now].first][p[now].second] = k;
          p[k] = p[now];
          op.push_back({a[i][j], now});
          k = a[i][j];
          p[a[i][j]] = {0, 0};
        }
        now++;
      }
    }
  }
  cout << op.size() << endl;
  for (auto i : op) {
    cout << i.first << " " << i.second << endl;
  }
}
