#include<bits/stdc++.h>
using namespace std;
const int N=2024;
int n,m,e,ans;
int vst[N][N];
bool ask[N];
int matched[N];
bool search(int x){
for(int j=1;j<=m;j++){
if(vst[x][j]){
if(ask[j]) continue;
ask[j]=1;
if(!matched[j]||search(matched[j])){
matched[j]=x;
return true;
}
}
}
return false;
}
void match(){
int cnt=0;
memset(matched,0,sizeof(matched));
for(int i=1;i<=m;i++){
memset(ask,0,sizeof(ask));
if(search(i)) cnt++;
}
cout<<cnt<<endl;
for(int i=1;i<=N;i++){
if(matched[i]){
cout<<matched[i]<<' '<<i+n<<endl;
}
}
return;
}
int main(){
cin>>n>>m;
m-=n;
while(1){
int x,y;
cin>>x>>y;
y-=n;
if(x==-1||y==-1) break;
vst[x][y]=1;
}
match();
return 0;
}