#include <bits/stdc++.h>
using namespace std;
int ni[222];
pair<int, int> cluster[222];
pair<int, int> answer[444];
int main() {
  memset(cluster, -1, sizeof cluster);
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d", ni + i);
    for (int j = 0; j < ni[i]; ++j) {
      int id;
      scanf("%d", &id);
      --id;
      cluster[id] = make_pair(i, j);
    }
  }
  int size = 0;
  int _3aleh_eldor = 0;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < ni[i]; ++j) {
      int fady = 0;
      for (int k = 0; k < n; ++k)
        if (cluster[k].first == -1) {
          fady = k;
          break;
        }
      int feen = 0;
      for (int k = 0; k < n; ++k)
        if (cluster[k] == make_pair(i, j)) {
          feen = k;
          break;
        }
      if (cluster[_3aleh_eldor].first != -1 && _3aleh_eldor != feen) {
        cluster[fady] = cluster[_3aleh_eldor];
        cluster[_3aleh_eldor] = make_pair(-1, -1);
        answer[size++] = make_pair(_3aleh_eldor + 1, fady + 1);
      }
      if (_3aleh_eldor != feen) {
        cluster[_3aleh_eldor] = cluster[feen];
        cluster[feen] = make_pair(-1, -1);
        answer[size++] = make_pair(feen + 1, _3aleh_eldor + 1);
      }
      _3aleh_eldor++;
    }
  }
  printf("%d\n", size);
  for (int i = 0; i < size; ++i) {
    printf("%d %d\n", answer[i].first, answer[i].second);
  }
  for (int i = 0; i < n; ++i) {
    fprintf(stderr, "(%d,%d)%c", cluster[i].first, cluster[i].second,
            " \n"[i == n - 1]);
  }
  return 0;
}
