#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, p = 0;
  cin >> n >> m;
  vector<int> vec(n, -1);
  vector<pair<int, int> > ans;
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    for (int j = 0; j < x; j++) {
      int t;
      cin >> t;
      --t;
      vec[t] = p;
      p++;
    }
  }
  for (int i = 0; i < p; i++) {
    if (i == vec[i]) continue;
    int emp, ind;
    for (int j = 0; j < vec.size(); j++) {
      if (vec[j] == -1) {
        emp = j;
        break;
      }
    }
    for (int j = 0; j < vec.size(); j++) {
      if (vec[j] == i) {
        ind = j;
        break;
      }
    }
    if (vec[i] != -1) {
      ans.push_back(make_pair(i + 1, emp + 1));
      vec[emp] = vec[i];
    }
    ans.push_back(make_pair(ind + 1, i + 1));
    vec[ind] = -1;
    vec[i] = i;
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first << " " << ans[i].second << endl;
}
