#include <bits/stdc++.h>
const int nmax = 205;
int v[nmax];
std::vector<int> l[nmax];
std::vector<std::pair<int, int> > ans;
int main() {
  int n, m, nr, z;
  std::cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    std::cin >> nr;
    while (nr--) {
      std::cin >> z;
      l[i].push_back(z);
      v[z] = i;
    }
  }
  int em, k = 1, cp = 0;
  for (int i = 1; i <= n; i++)
    if (v[i] == 0) em = i;
  for (int i = 1; i <= n; i++) {
    if (l[k][cp] != i) {
      int z = v[i];
      if (z == 0) {
        ans.push_back({l[k][cp], i});
        if (i == em) em = l[k][cp];
        v[l[k][cp]] = 0;
        v[i] = k;
        l[k][cp] = i;
      } else
        for (int j = 0; j < l[z].size(); j++)
          if (l[z][j] == i) {
            ans.push_back({l[z][j], em});
            ans.push_back({l[k][cp], i});
            l[z][j] = em;
            em = l[k][cp];
            l[k][cp] = i;
            v[l[z][j]] = z;
            v[em] = 0;
            v[i] = k;
            break;
          }
    }
    cp++;
    if (cp == l[k].size()) k++, cp = 0;
    if (k == m + 1) break;
  }
  std::cout << ans.size() << "\n";
  for (auto z : ans) std::cout << z.first << " " << z.second << "\n";
}
