#include <bits/stdc++.h>
using namespace std;
const double pi = 3.1415926535;
const double eps = 1e-6;
int n, m, a1, all, a2, Save[110000];
vector<int> ans;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &a2);
    for (int j = 0; j < a2; j++) {
      scanf("%d", &a1);
      Save[a1] = ++all;
    }
  }
  int f = 1;
  while (f) {
    f = 0;
    for (int i = 1; i <= n; i++)
      if (i <= all && Save[i] == 0) {
        for (int j = 1; j <= n; j++)
          if (Save[j] == i) {
            swap(Save[i], Save[j]);
            ans.push_back(j);
            ans.push_back(i);
            f = 1;
            break;
          }
        if (f) break;
      } else if (i > all && Save[i] == 0) {
        for (int j = 1; j <= all; j++)
          if (Save[j] != j) {
            swap(Save[i], Save[j]);
            ans.push_back(j);
            ans.push_back(i);
            f = 1;
            break;
          }
        if (f) break;
      }
  }
  printf("%d\n", ans.size() / 2);
  for (int i = 0; i < ans.size(); i++) {
    printf("%d", ans[i]);
    if (i & 1)
      puts("");
    else
      printf(" ");
  }
}
