#include <bits/stdc++.h>
using namespace std;
int a[100010];
int to[100010];
bool vis[100010];
int s[210];
int empty;
vector<pair<int, int> > ans;
pair<int, int> pp[100010];
int qq;
void solve(int x) {
  qq = 0;
  int pre = x;
  int now = to[x];
  while (now != x && now != -1) {
    pp[qq++] = make_pair(pre, now);
    pre = now;
    now = to[now];
    to[pre] = -1;
  }
  to[x] = -1;
  if (now == -1) {
    empty = x;
    for (int i = qq - 1; i >= 0; i--) ans.push_back(pp[i]);
  } else {
    ans.push_back(make_pair(pre, empty));
    for (int i = qq - 1; i >= 0; i--) ans.push_back(pp[i]);
    ans.push_back(make_pair(empty, x));
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  memset(vis, false, sizeof(vis));
  memset(to, -1, sizeof(to));
  int sum = 0;
  for (int i = 1; i <= m; i++) {
    scanf("%d", &s[i]);
    for (int j = 1; j <= s[i]; j++) {
      int t;
      scanf("%d", &t);
      to[t] = ++sum;
      vis[t] = true;
    }
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) empty = i;
  ans.clear();
  for (int i = 1; i <= n; i++)
    if (to[i] != i && to[i] != -1) solve(i);
  int len = ans.size();
  printf("%d\n", len);
  for (int i = 0; i < len; i++) printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
