#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[250];
int np[250], p[250][250];
int main(void) {
  int n, m;
  scanf("%d%d", &m, &n);
  for (int i = 1; i <= m; i++) a[i] = make_pair(-1, -1);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &np[i]);
    for (int j = 0; j < np[i]; j++) {
      scanf("%d", &p[i][j]);
      a[p[i][j]] = make_pair(i, j);
    }
  }
  int free = 0;
  for (int i = 1; i <= m; i++)
    if (a[i].first == -1) free = i;
  int C = 0;
  vector<pair<int, int> > ans;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < np[i]; j++) {
      ++C;
      if (p[i][j] == C) continue;
      if (a[C].first != -1) {
        pair<int, int> r = a[C];
        ans.push_back(make_pair(C, free));
        p[r.first][r.second] = free;
        a[C] = make_pair(-1, -1);
        a[free] = r;
      }
      free = C;
      ans.push_back(make_pair(p[i][j], free));
      a[p[i][j]] = make_pair(-1, -1);
      a[C] = make_pair(i, j);
      free = p[i][j];
      p[i][j] = C;
    }
  }
  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;
}
