#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const long long MOD = 1e9 + 7, SIZE = 1e5 * 2 + 10, P = 10000, P2 = 100000,
                MOD2 = 1e9 + 3, INF = 1e9 * 1e6 + 10;
vector<vector<long long>> vec;
long long n, m;
map<long long, long long> dv;
set<long long> nums;
long long used[203];
pair<long long, long long> cur[203];
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  ;
  cin >> n >> m;
  vec.resize(m);
  long long fr = -1;
  for (int i = 0; i < m; i++) {
    long long am;
    cin >> am;
    vec[i].resize(am);
    for (int j = 0; j < am; j++) {
      cin >> vec[i][j];
      vec[i][j]--;
      used[vec[i][j]] = (j + 1);
      cur[vec[i][j]] = {i, j};
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (!used[i]) fr = i;
  }
  long long i2 = 0;
  vector<pair<long long, long long>> ans;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < vec[i].size(); j++) {
      if (vec[i][j] == i2) {
        i2++;
        continue;
      } else {
        if (fr == i2) {
          used[fr] = j + 1;
          used[vec[i][j]] = 0;
          ans.push_back({vec[i][j], fr});
          swap(vec[i][j], fr);
        } else {
          ans.push_back({i2, fr});
          cur[fr] = {cur[i2]};
          swap(vec[cur[i2].first][cur[i2].second], fr);
          ans.push_back({vec[i][j], i2});
          swap(vec[i][j], fr);
        }
        i2++;
      }
    }
  }
  cout << ans.size() << "\n";
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i].first + 1 << " " << ans[i].second + 1 << "\n";
  }
  return 0;
}
