#include <bits/stdc++.h>
using namespace std;
bool lessp(const pair<int, int> &a, const pair<int, int> &b) {
  return a.first == b.first ? a.second < b.second : a.first < b.first;
}
int n, m, c_unused = 0;
vector<pair<int, int> > before, after, ans;
vector<int> repl;
pair<int, int> to_replace(-1, -1);
vector<bool> was;
void replace(int cur) {
  if (repl[cur] == cur) return;
  was[cur] = true;
  if (before[repl[cur]].first <= m)
    if (!was[repl[cur]])
      replace(repl[cur]);
    else {
      ans.push_back(make_pair(cur + 1, c_unused + 1));
      before[c_unused] = before[cur];
      before[cur] = make_pair(m + 1, m + 1);
      repl[c_unused] = repl[cur];
      repl[cur] = 0;
      c_unused = cur;
      return;
    }
  ans.push_back(make_pair(cur + 1, repl[cur] + 1));
  before[repl[cur]] = before[cur];
  before[cur] = make_pair(m + 1, m + 1);
  repl[repl[cur]] = repl[cur];
  repl[cur] = 0;
  c_unused = cur;
}
int main() {
  scanf("%d%d", &n, &m);
  before.resize(n, make_pair(m + 1, m + 1));
  for (int i = 0; i < m; i++) {
    int cnum;
    scanf("%d", &cnum);
    for (int j = 0; j < cnum; j++) {
      int ccl;
      scanf("%d", &ccl);
      before[ccl - 1] = make_pair(i + 1, j + 1);
    }
  }
  while (before[c_unused].first <= m) c_unused++;
  after = before;
  sort(after.begin(), after.end(), lessp);
  map<pair<int, int>, int> pos;
  for (int i = 0; i < n; i++)
    if (before[i].first <= m) pos[before[i]] = i;
  repl.resize(n);
  for (int i = 0; i < n; i++)
    if (after[i].first <= m) repl[pos[after[i]]] = i;
  was.resize(n);
  bool done = false;
  while (!done) {
    done = true;
    for (int i = 0; i < n; i++)
      if (before[i].first <= m && repl[i] != i) {
        for (int j = 0; j < n; j++) was[j] = false;
        replace(i);
        done = false;
      }
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++)
    printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
