#include <bits/stdc++.h>
using namespace std;
int n, m;
int from[205], to[205];
vector<pair<int, int> > note;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int ni;
    cin >> ni;
    for (int i = 0; i < ni; i++) {
      static int td = 1;
      int ind;
      int st = td;
      cin >> ind;
      from[td] = ind;
      to[ind] = td;
      td++;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (from[i] != 0 && to[i] == 0) {
      int c = i;
      while (from[c] != 0) {
        int a, b;
        note.push_back(make_pair(from[c], c));
        a = c;
        c = from[c];
        b = c;
        from[a] = 0;
        to[b] = 0;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (from[i] == i) continue;
    if (from[i] != 0) {
      int c = i;
      int t = to[i];
      note.push_back(make_pair(i, n));
      while (from[c] != 0) {
        int a, b;
        note.push_back(make_pair(from[c], c));
        a = c;
        c = from[c];
        b = c;
        from[a] = 0;
        to[b] = 0;
      }
      note.pop_back();
      note.push_back(make_pair(n, t));
    }
  }
  cout << note.size() << endl;
  for (int i = 0; i < note.size(); i++) {
    cout << note[i].first << " " << note[i].second << endl;
  }
  return 0;
}
