#include <bits/stdc++.h>
using namespace std;
int n, m, k, x[400], loc[400];
int main() {
  scanf("%d%d", &n, &m);
  memset(x, -1, sizeof(x));
  for (int _ = 0; _ < (int)(m); _++) {
    int num;
    scanf("%d", &num);
    for (int __ = 0; __ < (int)(num); __++) {
      int a;
      scanf("%d", &a);
      a--;
      x[a] = k;
      loc[k] = a;
      k++;
    }
  }
  int t = -1;
  for (int i = 0; i < (int)(n); i++)
    if (x[i] == -1) t = i;
  vector<pair<int, int> > ans;
  for (int i = 0; i < (int)(k); i++)
    if (x[i] != i) {
      if (x[i] != -1) {
        ans.push_back(make_pair(i, t));
        x[t] = x[i];
        loc[x[t]] = t;
      }
      ans.push_back(make_pair(loc[i], i));
      t = loc[i];
      x[t] = -1;
      x[i] = i;
      loc[x[i]] = i;
    }
  printf("%d\n", (int)ans.size());
  for (int i = 0; i < (int)(ans.size()); i++)
    printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
  return 0;
}
