#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int n, m;
vector<int> c, num, ni;
void solve() {
  int free = 0;
  while (c[free]) free++;
  vector<pair<int, int> > res;
  int placed = 0, i = 0;
  while (placed < m) {
    int j = i;
    while (c[j] == 0) j++;
    int file = c[j];
    for (int j = 0; j < ni[file]; j++) {
      int pos = 0;
      while (!(c[pos] == file && num[pos] == j)) {
        pos++;
      }
      if (i != pos) {
        if (c[i] == 0) {
          res.push_back(make_pair(pos, i));
          c[i] = c[pos];
          num[i] = num[pos];
          c[pos] = 0;
          free = pos;
        } else {
          res.push_back(make_pair(i, free));
          c[free] = c[i];
          num[free] = num[i];
          res.push_back(make_pair(pos, i));
          c[i] = c[pos];
          num[i] = num[pos];
          c[pos] = 0;
          free = pos;
        }
      }
      i++;
    }
    placed++;
  }
  cout << res.size() << endl;
  for (int i = 0; i < (int)res.size(); i++) {
    cout << res[i].first + 1 << ' ' << res[i].second + 1 << endl;
  }
}
int main() {
  while (cin >> n >> m) {
    c = vector<int>(n, 0);
    num = vector<int>(n);
    ni = vector<int>(m + 1);
    for (int i = 1; i <= m; i++) {
      cin >> ni[i];
      for (int j = 0; j < ni[i]; j++) {
        int p;
        cin >> p;
        p--;
        c[p] = i;
        num[p] = j;
      }
    }
    solve();
  }
}
