#include <bits/stdc++.h>
using namespace std;
const int INF = int(1e9);
const long long INFll = 1ll * INF * INF;
const int MOD = 1000000007;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<int> used(n + 1);
  vector<int> need(n + 1);
  int K = 0;
  for (int i = 1; i <= m; ++i) {
    int k;
    cin >> k;
    for (int j = 0; j < k; ++j) {
      int x;
      cin >> x;
      used[x] = ++K;
      need[K] = K;
    }
  }
  vector<pair<int, int> > ans;
  while (1) {
    int f = 0;
    for (int i = 1; i <= K; ++i)
      if (used[i] != need[i]) {
        f = i;
        break;
      }
    if (!f) break;
    int y = 0;
    for (int i = f; i <= n; ++i)
      if (used[i] == need[f]) {
        y = i;
        break;
      }
    int free = 0;
    for (int i = f + 1; i <= n; ++i)
      if (used[i] == 0) {
        free = i;
        break;
      }
    if (!free) {
      ans.push_back(make_pair(y, f));
      used[f] = used[y];
      used[y] = 0;
      continue;
    }
    ans.push_back(make_pair(f, free));
    ans.push_back(make_pair(y, f));
    used[free] = used[f];
    used[f] = used[y];
    used[y] = 0;
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); ++i)
    cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
