#include <bits/stdc++.h>
using namespace std;
const int N = 205;
int a[N][N], b[N * N];
vector<pair<int, int> > ans;
int len[N];
void go(int x, int y) {
  b[y] = b[x];
  b[x] = 0;
  int i = b[y] / N, j = b[y] % N;
  a[i][j] = y;
  ans.push_back(make_pair(x, y));
  return;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> len[i];
    for (int j = 1; j <= len[i]; j++) {
      cin >> a[i][j];
      b[a[i][j]] = i * N + j;
    }
  }
  int cur = 1;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= len[i]; j++) {
      if (b[cur]) {
        for (int k = cur + 1; k <= n; k++) {
          if (!b[k]) {
            go(cur, k);
            break;
          }
        }
      }
      go(a[i][j], cur);
      cur++;
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}
