#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[202];
int s;
int b[202];
int ans[202 + 202][2], l;
inline int get(int pos, int x) {
  for (int i = pos; i < n; ++i)
    if (a[i] == x) return i;
  assert(0);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0, p = 0; i < m; ++i) {
    int t;
    scanf("%d", &t);
    b[i] = t;
    s += t;
    for (int j = 0; j < t; ++j) {
      int tt;
      scanf("%d", &tt);
      a[tt - 1] = ++p;
    }
  }
  for (int i = 0; i < s; ++i)
    if (a[i] != i + 1) {
      int fr = get(0, 0);
      int fi = get(0, i + 1);
      if (fr == i) {
        a[i] = a[fi];
        a[fi] = 0;
        ans[l][0] = fi;
        ans[l++][1] = i;
      } else {
        a[fr] = a[i];
        a[i] = 0;
        ans[l][0] = i;
        ans[l++][1] = fr;
        a[i] = a[fi];
        a[fi] = 0;
        ans[l][0] = fi;
        ans[l++][1] = i;
      }
    }
  printf("%d\n", l);
  for (int i = 0; i < l; ++i) printf("%d %d\n", ans[i][0] + 1, ans[i][1] + 1);
  return 0;
}
