#include <bits/stdc++.h>
using namespace std;
const int nmax = 205;
pair<int, int> a[nmax];
int files[nmax][nmax];
vector<int> emp;
vector<pair<int, int> > ans;
int main() {
  int n, m, i, j, k;
  cin >> n >> m;
  for (i = 0; i < n; i++) a[i].first = 205;
  for (i = 0; i < m; i++) {
    cin >> files[i][0];
    for (j = 1; j <= files[i][0]; j++) {
      cin >> files[i][j];
      files[i][j]--;
      a[files[i][j]].first = i;
      a[files[i][j]].second = j;
    }
  }
  for (i = 0; i < n; i++)
    if (a[i].first == 205) emp.push_back(i);
  k = 0;
  for (i = 0; i < m; i++) {
    for (j = 1; j <= files[i][0]; j++) {
      if (files[i][j] == k) {
        k++;
        continue;
      }
      if (a[k].first == 205) {
        ans.push_back(make_pair(files[i][j], k));
        for (int h = 0; h < emp.size(); h++) {
          if (emp[h] == k) {
            emp[h] = files[i][j];
            break;
          }
        }
        swap(a[files[i][j]], a[k]);
      } else {
        int h = emp[0];
        pair<int, int> tmp;
        tmp = a[h];
        a[h] = a[k];
        a[k] = a[files[i][j]];
        a[files[i][j]] = tmp;
        files[a[h].first][a[h].second] = h;
        ans.push_back(make_pair(k, h));
        ans.push_back(make_pair(files[i][j], k));
        emp[0] = files[i][j];
      }
      k++;
    }
  }
  cout << ans.size() << endl;
  for (i = 0; i < ans.size(); i++) {
    cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;
  }
  return 0;
}
