#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, a[N], c[N];
int main() {
  int r = 1;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> c[i];
    for (int j = 0; j < c[i]; j++) {
      int k;
      cin >> k;
      a[k] = r++;
    }
    c[i] += c[i - 1];
  }
  vector<pair<int, int> > ans;
  for (int i = 1; i <= c[m]; i++) {
    if (a[i] == i) continue;
    if (a[i]) {
      for (int j = i + 1; j <= n; j++) {
        if (a[j] == 0) {
          ans.push_back(make_pair(i, j));
          swap(a[i], a[j]);
          break;
        }
      }
    }
    for (int j = i + 1; j <= n; j++) {
      if (a[j] == i) {
        ans.push_back(make_pair(j, i));
        swap(a[i], a[j]);
        break;
      }
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
