#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n + 1);
  long long id = 1;
  for (long long i = 0; i < m; i++) {
    long long x, c;
    cin >> x;
    for (long long j = 0; j < x; j++) cin >> c, a[c] = id++;
  }
  vector<pair<long long, long long> > ans;
  for (long long i = 1; i < id; i++) {
    long long free = find(a.begin() + 1, a.end(), 0) - a.begin();
    long long cur = find(a.begin() + 1, a.end(), i) - a.begin();
    long long next = i;
    if (cur == next) continue;
    if (next != free) ans.emplace_back(next, free);
    ans.emplace_back(cur, next);
    a[cur] = 0;
    a[free] = a[next];
    a[next] = next;
  }
  cout << (long long)ans.size() << endl;
  for (auto i : ans) cout << i.first << " " << i.second << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
