#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:64000000")
template <class T>
inline T sqr(T x) {
  return x * x;
}
int n, m;
vector<vector<int> > a;
char used[1 << 10];
int id[1 << 10];
vector<pair<int, int> > ans;
int main() {
  scanf("%d%d", &n, &m);
  a.resize(m);
  for (int i = 0; i < m; ++i) {
    int k;
    scanf("%d", &k);
    a[i].resize(k);
    for (int j = 0; j < k; ++j) {
      scanf("%d", &a[i][j]);
      --a[i][j];
      used[a[i][j]] = true;
      id[a[i][j]] = i;
    }
  }
  int free = -1;
  for (int i = 0; i < n; ++i)
    if (!used[i]) free = i;
  int sum = 0;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < (int)((a[i]).size()); ++j) {
      int cur = a[i][j];
      int to = sum + j;
      if (cur != to) {
        if (to != free) {
          ans.push_back(make_pair(to, free));
          for (int k = 0; k < (int)((a[id[to]]).size()); ++k) {
            if (a[id[to]][k] == to) {
              a[id[to]][k] = free;
              id[free] = id[to];
              break;
            }
          }
        }
        ans.push_back(make_pair(cur, to));
        a[i][j] = to;
        id[to] = i;
        free = cur;
      }
    }
    sum += (int)((a[i]).size());
  }
  if ((int)((ans).size()) > 2 * n) ++*(int*)0;
  printf("%d\n", (int)((ans).size()));
  for (int i = 0; i < (int)((ans).size()); ++i)
    printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
  return 0;
}
