#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
const ll inf=1000000000;
ll n,m;
const ll N=110,M=6000;
ll h[N],ne[M],e[M],f[M],idx,d[N],cur[N];
void add(ll u,ll v,ll w){
e[idx]=v,ne[idx]=h[u],f[idx]=w,h[u]=idx++;
e[idx]=u,ne[idx]=h[v],f[idx]=0,h[v]=idx++;
}
bool bfs(){
queue <ll> q;
q.push(0);
memset(d,-1,sizeof d);
d[0]=0;cur[0]=h[0];
while(q.size()){
ll t=q.front();
q.pop();
for(int i=h[t];i!=-1;i=ne[i]){
int ver=e[i];
if(d[ver]==-1 && f[i]){
d[ver]=d[t]+1;
cur[ver]=h[ver];
if(ver==n+1) return true;
q.push(ver);
}
}
}
return false;
}
ll find(ll u,ll limit){
if(u==n+1) return limit;
ll flow=0;
for(int i=cur[u] ; i!=-1 && flow <limit ;i=ne[i]){
cur[u]=i;
int ver=e[i];
if(d[ver]==d[u]+1 && f[i]){
ll t=find(ver,min(f[i],limit-flow));
if(t==0) d[ver]=-1;
f[i]-=t;f[i^1]+=t;flow+=t;
}
}
return flow;
}
int main(){
cin>>m>>n;
idx=0;
memset(h,-1,sizeof h);
ll u,v;
while(cin>>u>>v){
if(u==-1) break;
add(u,v,1);
}
for(ll i=1;i<=m;i++){
add(0,i,1);
}
for(ll i=m+1;i<=n;i++){
add(i,n+1,1);
}
ll ans=0,flow;
while(bfs()) while(flow = find(0,inf)) ans+=flow;
cout<<ans<<endl;
for(ll i=0;i<idx;i+=2){
if(e[i]>m && e[i]<=n && !f[i]){
cout<<e[i^1]<<' '<<e[i]<<endl;
}
}
return 0;
}