#include <bits/stdc++.h>
using namespace std;
struct Node {
  int from;
  int to;
  Node(int ffrom, int tto) {
    from = ffrom;
    to = tto;
  };
  Node(){};
};
queue<Node> ans;
bool vis[250];
int n, m;
int a[250];
void init() {
  memset(vis, 0, sizeof(vis));
  memset(a, 0x3f3f3f3f, sizeof(a));
}
int main() {
  scanf("%d%d", &n, &m);
  init();
  int cnt = 0;
  int free;
  for (int i = 1; i <= m; ++i) {
    int t, temp;
    scanf("%d", &t);
    while (t--) {
      scanf("%d", &temp);
      a[temp] = ++cnt;
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i] == 0x3f3f3f3f) {
      free = i;
      break;
    }
  }
  for (int i = 1; i <= n - 1; ++i) {
    int minPos = i;
    int minx = a[i];
    for (int j = i + 1; j <= n; ++j) {
      if (a[j] < minx) {
        minPos = j;
        minx = a[j];
      }
    }
    if (minPos != i) {
      if (a[i] != 0x3f3f3f3f) {
        ans.push(Node(i, free));
        a[free] = a[i];
      }
      ans.push(Node(minPos, i));
      a[i] = a[minPos];
      a[minPos] = 0x3f3f3f3f;
      free = minPos;
    }
  }
  printf("%lu\n", ans.size());
  while (!ans.empty()) {
    Node temp = ans.front();
    ans.pop();
    printf("%d %d\n", temp.from, temp.to);
  }
}
