#include <bits/stdc++.h>
using namespace std;
const int N=110, M=(N*N+2*N)*2, inf=1e9;
int ver[M],nxt[M],fl[M],head[2*N],tot=1;
int q[2*N],d[2*N],nh[2*N];
int n,m,S,T;
void add(int x,int y,int z){
ver[++tot]=y,fl[tot]=z,nxt[tot]=head[x],head[x]=tot;
}
bool bfs(){
memset(d,0,sizeof d);
d[S]=1,q[0]=S,nh[S]=head[S];
int hh=0,tt=1;
while(hh<tt){
int x=q[hh++];
for(int i=head[x];i;i=nxt[i]){
int y=ver[i];
if(d[y] || !fl[i])continue;
d[y]=d[x]+1, nh[y]=head[y];
if(y==T)return true;
q[tt++]=y;
}
}
return false;
}
int find(int x,int limit){
if(x==T)return limit;
int flow=0;
for(int i=nh[x];i && flow<limit;i=nxt[i]){
nh[x]=i;
int y=ver[i];
if(d[y]!=d[x]+1 || !fl[i])continue;
int t=find(y,min(fl[i],limit-flow));
if(t)flow+=t, fl[i]-=t, fl[i^1]+=t;
else d[y]=0;
}
return flow;
}
int dinic(){
int res=0,flow;
for(;bfs();)
while(flow=find(S,inf))res+=flow;
return res;
}
int main(){
cin>>m>>n;
int x,y;
while(cin>>x>>y, x!=-1)
add(x,m+y,1), add(m+y,x,0);
S=0, T=n+m+1;
for(int i=1;i<=m;i++)
add(S,i,1), add(i,S,0);
for(int i=1;i<=n;i++)
add(m+i,T,1), add(T,m+i,0);
cout<<dinic()<<endl;
for(int i=2;i<=tot;i+=2){
x=ver[i^1], y=ver[i];
if(x<1 || x>m || y<=m || y==T)continue;
if(fl[i])continue;
cout<<x<<" "<<y-m<<endl;
}
return 0;
}