#include <bits/stdc++.h>
using namespace std;
const int DX[8] = {1, -1, 0, 0, 1, 1, -1, -1};
const int DY[8] = {0, 0, 1, -1, 1, -1, 1, -1};
const int intmax = 0x7fffffff;
const int mod = 1000000007;
int n, m;
int f[205];
int p[205];
vector<pair<int, int> > op;
int main() {
  scanf("%d%d", &n, &m);
  int cnt = 0;
  for (int i = 0; i < m; i++) {
    int nk;
    scanf("%d", &nk);
    for (int j = 0; j < nk; j++) {
      int a;
      scanf("%d", &a);
      cnt++;
      f[a] = cnt;
      p[cnt] = a;
    }
  }
  int pemp;
  for (int i = 1; i <= n; i++)
    if (!f[i]) pemp = i;
  for (int j = 1; j <= cnt; j++) {
    if (f[j] != j) {
      if (!f[j] || j == pemp) {
        pemp = p[j];
        op.push_back(make_pair(p[j], j));
        p[j] = j;
        f[j] = j;
        continue;
      }
      f[pemp] = f[j];
      p[f[j]] = pemp;
      op.push_back(make_pair(j, pemp));
      int now = j;
      while (f[now] != now && now <= cnt && now >= 1) {
        op.push_back(make_pair(p[now], now));
        int tmp = now;
        f[now] = now;
        now = p[now];
        p[tmp] = tmp;
      }
      pemp = now;
    }
  }
  printf("%d\n", op.size());
  for (int i = 0; i < op.size(); i++) {
    printf("%d %d\n", op[i].first, op[i].second);
  }
}
