#include <bits/stdc++.h>
using namespace std;
int searchEmptyLoc(vector<pair<int, int> > &clusters) {
  for (int i = 0; i < (int)clusters.size(); ++i) {
    if (clusters[i].first == 0 && clusters[i].second == 0) return i;
  }
  return 0;
}
int searchForFrag(vector<pair<int, int> > &clusters, int k, int j) {
  for (int i = 0; i < (int)clusters.size(); ++i) {
    if (clusters[i].first == k && clusters[i].second == j) {
      return i;
    }
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> files(m);
  vector<pair<int, int> > clusters(n, make_pair(0, 0));
  for (int i = 0, cnt, clust; i < m; ++i) {
    cin >> cnt;
    files[i] = cnt;
    while (cnt--) {
      cin >> clust;
      clusters[clust - 1] = make_pair(i + 1, files[i] - cnt - 1);
    }
  }
  vector<pair<int, int> > swapping;
  int loc = 0;
  for (int i = 1; i <= m; ++i) {
    for (int j = 0; j < files[i - 1]; ++j) {
      int frag_loc = searchForFrag(clusters, i, j);
      if (frag_loc == loc) {
        loc++;
      } else {
        int emp_loc = searchEmptyLoc(clusters);
        if (loc != emp_loc) {
          swapping.push_back(make_pair(loc + 1, emp_loc + 1));
          clusters[emp_loc] = clusters[loc];
          clusters[loc] = make_pair(0, 0);
        }
        swapping.push_back(make_pair(frag_loc + 1, loc + 1));
        clusters[loc] = clusters[frag_loc];
        clusters[frag_loc] = make_pair(0, 0);
        loc++;
      }
    }
  }
  cout << swapping.size() << endl;
  for (int k = 0; k < (int)swapping.size(); ++k) {
    cout << swapping[k].first << ' ' << swapping[k].second << endl;
  }
  return 0;
}
