#include <bits/stdc++.h>
using namespace std;
const int MAXN = 201;
int n, m, fr, len, c, fnow, pnow;
vector<int> f[MAXN];
int l[MAXN];
pair<int, int> p[MAXN];
vector<pair<int, int> > ans;
int main() {
  scanf("%d %d\n", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &len);
    l[i] = len;
    for (int j = 0; j < len; j++) {
      scanf("%d", &c);
      f[i].push_back(c);
      p[c] = make_pair(i, j);
    }
  }
  for (int i = 1; i <= n; i++)
    if (p[i].first == 0) fr = i;
  fnow = 1;
  pnow = 0;
  for (int i = 1; i <= n; i++) {
    if (pnow == l[fnow]) {
      fnow++;
      pnow = 0;
      if (fnow > m) break;
    }
    int pos = f[fnow][pnow];
    if (i == pos) {
      pnow++;
      continue;
    }
    if (p[i] == make_pair(0, 0)) {
      ans.push_back(make_pair(pos, i));
      f[fnow][pnow] = i;
      p[i] = p[pos];
      p[pos] = make_pair(0, 0);
      fr = pos;
    } else {
      ans.push_back(make_pair(i, fr));
      f[p[i].first][p[i].second] = fr;
      p[fr] = p[i];
      p[i] = make_pair(0, 0);
      fr = i;
      ans.push_back(make_pair(pos, fr));
      f[fnow][pnow] = i;
      p[i] = p[pos];
      p[pos] = make_pair(0, 0);
      fr = pos;
    }
    pnow++;
  }
  printf("%d\n", (int)ans.size());
  for (int i = 0; i < (int)ans.size(); i++)
    printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
