#include <bits/stdc++.h>
using namespace std;
int n, m, l[300], a[300][300];
vector<pair<int, int> > ans;
set<int> second;
pair<int, int> x[300];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) second.insert(i);
  for (int i = 1; i <= m; ++i) {
    scanf("%d", &l[i]);
    for (int j = 1; j <= l[i]; ++j) {
      scanf("%d", &a[i][j]);
      x[a[i][j]] = make_pair(i, j);
      second.erase(a[i][j]);
    }
  }
  int pos = 0;
  for (int i = 1; i <= m; ++i) {
    for (int j = 1; j <= l[i]; ++j) {
      ++pos;
      if (a[i][j] == pos) {
        continue;
      }
      if (second.find(pos) != second.end()) {
        ans.push_back(make_pair(a[i][j], pos));
        second.erase(pos);
        second.insert(a[i][j]);
        x[a[i][j]] = make_pair(0, 0);
        x[pos] = make_pair(i, j);
      } else {
        int y = *(--second.end());
        ans.push_back(make_pair(pos, y));
        ans.push_back(make_pair(a[i][j], pos));
        second.erase(y);
        second.insert(a[i][j]);
        pair<int, int> z = x[pos];
        x[pos] = make_pair(i, j);
        x[y] = make_pair(z.first, z.second);
        a[z.first][z.second] = y;
      }
    }
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < (int)ans.size(); ++i)
    printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
