#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> v(n + 1);
  vector<pair<int, int>> ans;
  int cnt = 0, tot = 0;
  for (int i = 0; i < m; i++) {
    int k, num;
    cin >> k;
    for (int j = 0; j < k; j++) {
      cin >> num;
      v[num] = ++cnt;
    }
    tot += k;
  }
  int tmp = 0;
  for (int i = 1; i <= n; i++) {
    if (v[i] == 0) {
      tmp = i;
      break;
    }
  }
  for (int i = 1; i <= tot; i++) {
    if (v[i] != i) {
      int tmp2 = i;
      for (int j = i + 1; j <= n; j++) {
        if (v[j] == i) {
          tmp2 = j;
          break;
        }
      }
      if (i != tmp) ans.push_back({i, tmp});
      ans.push_back({tmp2, i});
      v[tmp] = v[i];
      v[i] = i;
      tmp = tmp2;
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first << " " << ans[i].second << endl;
}
