#include <bits/stdc++.h>
using namespace std;
long long a[100001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m, cnt = 0, i = 0, j = 0, k = 0;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int x;
    cin >> x;
    while (x--) {
      int y;
      cin >> y;
      a[y] = ++cnt;
    }
  }
  vector<pair<int, int>> ans;
  for (k = 1; k <= n; ++k) {
    if (a[k] == 0) {
      break;
    }
  }
  for (i = 1; i <= cnt; ++i) {
    if (a[i] != i) {
      for (j = i + 1; j <= n; ++j) {
        if (a[j] == i) break;
      }
      if (i != k) {
        ans.push_back(make_pair(i, k));
      }
      ans.push_back(make_pair(j, i));
      a[k] = a[i];
      a[i] = i;
      k = j;
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size();
       cout << ans[i].first << " " << ans[i].second << endl, ++i)
    ;
}
