#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > file(203);
  vector<vector<int> > v(203);
  bool f[203];
  for (int i = 0; i <= n; i++) {
    f[i] = false;
    file[i] = make_pair(-1, -1);
  }
  int free = 0;
  for (int i = 0; i < m; i++) {
    int n1;
    cin >> n1;
    free += n1;
    for (int j = 0; j < n1; j++) {
      int a;
      cin >> a;
      f[a] = true;
      file[a] = make_pair(i, j);
      v[i].push_back(a);
    }
  }
  for (int i = 1; i <= n; i++)
    if (f[i] == false) {
      free = i;
      break;
    }
  vector<pair<int, int> > ans;
  int which = 1;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < v[i].size(); j++) {
      if (free == which || f[which] == false) {
        for (int k = which + 1; k <= n; k++) {
          if (file[k] == pair<int, int>(i, j)) {
            ans.push_back(make_pair(k, which));
            f[k] = false;
            file[k] = make_pair(-1, -1);
            free = k;
            f[k] = false;
            break;
          }
        }
        which++;
        continue;
      }
      if (file[which] == pair<int, int>(i, j)) {
        which++;
        continue;
      }
      for (int k = which + 1; k <= n; k++) {
        if (file[k] == pair<int, int>(i, j)) {
          ans.push_back(make_pair(which, free));
          ans.push_back(make_pair(k, which));
          file[free] = file[which];
          file[which] = file[k];
          file[k] = make_pair(-1, -1);
          f[free] = true;
          f[which] = true;
          f[k] = false;
          free = k;
          break;
        }
      }
      which++;
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first << " " << ans[i].second << endl;
}
