#include <bits/stdc++.h>
using namespace std;
vector<int> a[200];
vector<pair<int, int> > owner;
vector<bool> solved;
vector<pair<int, int> > ans;
int n, m;
void solve(int who) {
  int dest_place = 0;
  while (owner[dest_place].first != -1 && owner[dest_place].first != who)
    dest_place++;
  int look = 0;
  while (look < a[who].size()) {
    int init_place = 0;
    for (int j = 0; j < n; ++j) {
      if (owner[j] == make_pair(who, look)) {
        init_place = j;
        break;
      }
    }
    int free_place = 0;
    for (int j = 0; j < n; ++j) {
      if (owner[j] == make_pair(-1, -1)) {
        free_place = j;
        break;
      }
    }
    if (init_place != dest_place) {
      if (free_place != dest_place) {
        owner[free_place] = owner[dest_place];
        owner[dest_place] = make_pair(-1, -1);
        ans.push_back(make_pair(dest_place, free_place));
      }
      owner[dest_place] = owner[init_place];
      owner[init_place] = make_pair(-1, -1);
      ans.push_back(make_pair(init_place, dest_place));
    }
    ++dest_place, ++look;
  }
  solved[who] = true;
}
int main() {
  scanf("%d %d", &n, &m);
  owner.assign(n, make_pair(-1, -1));
  solved.assign(m, false);
  for (int i = 0; i < m; ++i) {
    int sz;
    scanf("%d", &sz);
    a[i].resize(sz);
    for (int j = 0; j < sz; ++j) {
      scanf("%d", &a[i][j]);
      --a[i][j];
      owner[a[i][j]] = make_pair(i, j);
    }
  }
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; ++j) {
      if (owner[j].first != -1 && !solved[owner[j].first]) {
        solve(owner[j].first);
        break;
      }
    }
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); ++i) {
    printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
  }
  return 0;
}
