#include <bits/stdc++.h>
#define F(i,j,k) for(int i=(j);i<=(k);++i)
#define D(i,j,k) for(int i=(j);i>=(k);--i)
#define rep(it,s) for(__typeof(s.begin()) it=s.begin();it!=s.end();++it)
#define Rep(a,s) for(auto a:s)
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
namespace IO{
    template <class T>
    inline void read(T &x){
        x=0;int f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch<='9'&&ch>='0')x=x*10+ch-'0',ch=getchar();
        x*=f;
    }
};
using namespace IO;
const int N=100005;
vector<int>E[N];
int vis[N],fa[N];
set<pair<int,int>>setE;
vector<pair<int,int>>ans;
void add(int x,int y){E[x].PB(y);}
void dfs1(int x,int f){
	vis[x]=-1;
	fa[x]=f;
	Rep(y,E[x]){
		if(y==f)continue;
		if(vis[y]==-1){
			int pos=x;
			while(pos!=y){
				int u0=pos,v0=fa[pos];
				if(u0>v0)swap(u0,v0);
				setE.erase(MP(u0,v0));
				pos=fa[pos]; 
			}
			int u0=x,v0=y;
			if(u0>v0)swap(u0,v0);
			setE.erase(MP(u0,v0));
		}
		else if(!vis[y])dfs1(y,x);
	}
	vis[x]=1;
}
int dfs2(int x,int f){
	vis[x]=1;
	vector<int>vec;
	int flag=0;
	Rep(y,E[x]){
		if(y==f)continue;
		//dfs2(y,f);
		int ret=dfs2(y,x);
		if(ret==y&&(E[x].size()&1)&&flag==0){
			flag=1;
		}
		else vec.PB(ret);
	}
	while(vec.size()){
		if(vec.size()==1){
			if((E[x].size()&1)&&!flag)return ans.PB(MP(x,vec[vec.size()-1])),0;
			else return vec[vec.size()-1]; 
		}
		ans.PB(MP(vec[vec.size()-1],vec[vec.size()-2]));
		vec.pop_back();
		vec.pop_back();
	}
	return x;
}
int n,m;
void solve(){
	F(i,1,n)E[i].clear(),fa[i]=0,vis[i]=0;
	setE.clear();
	int K,tu,tv;
	//cout<<n<<' '<<m<<endl;
	F(i,1,m){
		cin>>K;
		F(_,1,K){
			cin>>tu;
			if(_>1){
				add(tu,tv),add(tv,tu);
				if(tu>tv)setE.insert(MP(tv,tu));
				else setE.insert(MP(tu,tv));
			}
			tv=tu;
		}
	}
	//Rep(y,setE){
	//	cout<<"edge1= "<<y.FF<<' '<<y.SS<<endl;
	//}
	dfs1(1,0);
	F(i,1,n)E[i].clear(),vis[i]=0;
	Rep(y,setE){
		//cout<<"edge2= "<<y.FF<<' '<<y.SS<<endl;
		add(y.FF,y.SS),add(y.SS,y.FF);
	}
	ans.clear();
	F(i,1,n){
		if(!vis[i])dfs2(i,0);
	}
	cout<<ans.size()<<'\n';
	Rep(y,ans)cout<<y.FF<<' '<<y.SS<<'\n';
}
int main(){
    #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
    #endif
    while(cin>>n>>m){
    	if(!n)break;
    	solve();
	}
    return 0;
}