#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
  int i,j,k,l,m;
  int n;
  while(cin>>n,n){
    vector<vector<int> > a;
    for(i=0;i<n;++i)
      a.push_back(vector<int>(1,i+1));
    int p,q;
    while(cin>>p>>q,p||q){      
      for(i=0;i<(int)a.size();++i){
	for(j=0;j<(int)a[i].size();++j){
	  if(a[i][j]==p)
	    break;
	}
	if(j<(int)a[i].size())
	  break;
      }
      if(q){
	for(k=0;k<(int)a.size();++k){
	  for(l=0;l<(int)a[k].size();++l){
	    if(a[k][l]==q)
	      break;
	  }
	  if(l<(int)a[k].size())
	    break;
	}
	if(i==k){
	  if(j<l){
	    for(m=j+1;m<(int)a[i].size();++m)
	      a.push_back(vector<int>(1,a[i][m]));
	    a[i-j+l].push_back(a[i][j]);
	    if(j){
	      a[i].erase(a[i].begin()+j,a[i].end());
	    }else{
	      a.erase(a.begin()+i);
	    }
	  }
	}else{
	  if((int)a[i].size()-1!=j){
	    for(m=j+1;m<(int)a[i].size();++m)
	      a.push_back(vector<int>(1,a[i][m]));
	  }
	  a[k].push_back(a[i][j]);
	  if(j){
	    a[i].erase(a[i].begin()+j,a[i].end());
	  }else{
	    a.erase(a.begin()+i);
	  }
	}
      }else{
	if(j){
	  if((int)a[i].size()-1!=j){
	    for(m=j+1;m<(int)a[i].size();++m)
	      a.push_back(vector<int>(1,a[i][m]));
	  }
	  a.push_back(vector<int>(1,a[i][j]));
	  a[i].erase(a[i].begin()+j,a[i].end());
	}
      }
    }
    vector<int> b;
    for(i=0;i<(int)a.size();++i)
      b.push_back(a[i].size());
    sort(b.begin(),b.end());
    for(i=0;i<(int)b.size();++i)
      cout<<b[i]<<endl;
    cout<<"end"<<endl;
  }
  return 0;
}