#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<vector<int> > file(n);
  for (int i = (0); i < ((m)); ++i) {
    int tmp;
    cin >> tmp;
    vector<int> f(tmp);
    for (int j = (0); j < ((tmp)); ++j) cin >> f[j];
    file.push_back(f);
  }
  vector<int> v;
  for (int i = (0); i < ((file.size())); ++i)
    for (int j = (0); j < ((file[i].size())); ++j) v.push_back(file[i][j]);
  sort((v).begin(), (v).end());
  int emp = v.size() + 1;
  for (int i = (0); i < ((v.size())); ++i) {
    if (i + 1 != v[i]) {
      emp = i + 1;
      break;
    }
  }
  int index = 1;
  vector<pair<int, int> > res;
  for (int i = (0); i < ((file.size())); ++i) {
    for (int j = (0); j < ((file[i].size())); ++j) {
      for (int k = (0); k < ((file.size())); ++k) {
        for (int l = (0); l < ((file[k].size())); ++l) {
          if (file[k][l] == index) {
            if (i != k || j != l) {
              int tmp;
              res.push_back(make_pair(file[k][l], emp));
              res.push_back(make_pair(file[i][j], index));
              tmp = file[k][l];
              file[k][l] = emp;
              emp = file[i][j];
              file[i][j] = tmp;
            }
            ++index;
            goto NEXT;
          }
        }
      }
      res.push_back(make_pair(file[i][j], index));
      emp = file[i][j];
      file[i][j] = index;
      ++index;
    NEXT:;
    }
  }
  cout << res.size() << endl;
  for (int i = (0); i < ((res.size())); ++i)
    cout << res[i].first << " " << res[i].second << endl;
}
