#include <bits/stdc++.h>
using namespace std;
int arr[201], cur, num[201], total, fil[201][201], ans[2][404];
int n, m, pos, k;
int main() {
  cin >> n >> m;
  memset(arr, 0, sizeof(arr));
  for (int i = 1; i <= m; i++) {
    cin >> num[i];
    for (int j = 1; j <= num[i]; j++) {
      cin >> fil[i][j];
      arr[fil[i][j]] = 209 * i + j;
    }
  }
  for (int i = 1; i <= n; i++)
    if (arr[i] == 0) {
      cur = i;
      break;
    }
  pos = 1;
  total = 1;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= num[i]; j++, pos++) {
      if (fil[i][j] == pos) continue;
      if (pos != cur) {
        ans[0][total] = pos;
        ans[1][total++] = cur;
      }
      ans[0][total] = fil[i][j];
      ans[1][total++] = pos;
      arr[cur] = arr[pos];
      k = fil[i][j];
      arr[pos] = arr[fil[i][j]];
      fil[arr[cur] / 209][arr[cur] % 209] = cur;
      fil[arr[pos] / 209][arr[pos] % 209] = pos;
      cur = k;
      arr[cur] = 0;
    }
  }
  cout << total - 1 << endl;
  for (int i = 1; i < total; i++) {
    cout << ans[0][i] << " " << ans[1][i] << endl;
  }
  return 0;
}
