#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include<cmath>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> v;
	for (int i = 0; i < n; ++i)
	{int f;
		cin>>f;
		v.push_back(f);
		/* code */
	}
	sort(v.begin(),v.end());
	if(k==0)
	{if(v[0]==1)
	    cout<<"-1"<<"\n";
	    else if(v[0]-1<=pow(10,9))
	    cout<<v[0]-1<<"\n";
	    else cout<<"-1"<<"\n";
	}
	else{

	if(v[k-1]!=v[k])
	{ if(v[k-1]<=pow(10,9))
        cout<<v[k-1]<<"\n";
        else cout<<"-1"<<"\n";
	}
	else if(v[k-1]==v[k])
	{
		cout<<"-1"<<"\n";
	}
}
}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include<cmath>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> v;
	for (int i = 0; i < n; ++i)
	{int f;
		cin>>f;
		v.push_back(f);
		/* code */
	}
	sort(v.begin(),v.end());
	if(k==0)
	{if(v[0]==1)
	    cout<<"-1"<<"\n";
	    else if(v[0]-1>=pow(10,9))
	    cout<<v[0]-1<<"\n";
	    else cout<<"-1"<<"\n";
	}
	else{

	if(v[k-1]!=v[k])
	{ if(v[k-1]>=pow(10,9))
        cout<<v[k-1]<<"\n";
        else cout<<"-1"<<"\n";
	}
	else
	{
		cout<<"-1"<<"\n";
	}
}
}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include<cmath>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> v;
	for (int i = 0; i < n; ++i)
	{int f;
		cin>>f;
		v.push_back(f);
		/* code */
	}
	sort(v.begin(),v.end());
	if(k==0)
	{if(v[0]==1)
	    cout<<"-1"<<"\n";
	    else if(v[0]-1>=pow(10,9))
	    cout<<v[0]-1<<"\n";
	    else cout<<"-1"<<"\n";
	}
	else{

	if(v[k-1]!=v[k])
	{ if(v[k-1]>=pow(10,9))
        cout<<v[k-1]<<"\n";
        else cout<<"-1"<<"\n";
	}
	else if(v[k-1]==v[k])
	{
		cout<<"-1"<<"\n";
	}
}
}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> v;
	for (int i = 0; i < n; ++i)
	{int f;
		cin>>f;
		v.push_back(k);
		/* code */
	}
	sort(v.begin(),v.end());

	if(v[k-1]==v[k])
	{
        cout<<"-1"<<"\n";
	}
	else
	{
		cout<<v[k-1]+1<<"\n";
	}

}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> v;
	for (int i = 0; i < n; ++i)
	{int f;
		cin>>f;
		v.push_back(f);
		/* code */
	}
	sort(v.begin(),v.end());

        cout<<v[k-1]+1<<"\n";

}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include<cmath>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> v;
	for (int i = 0; i < n; ++i)
	{int f;
		cin>>f;
		v.push_back(f);
		/* code */
	}
	sort(v.begin(),v.end());
	if(k==0)
	{if(v[0]==1)
	    cout<<"-1"<<"\n";
	    else if(v[0]-1>=pow(10,9))
	    cout<<v[0]-1<<"\n";
	    else cout<<"-1<<"\n":
	}
	else{

	if(v[k-1]!=v[k])
	{ if(v[k-1]>=pow(10,9))
        cout<<v[k-1]<<"\n";
        else cout<<"-1"<<"\n";
	}
	else
	{
		cout<<"-1"<<"\n";
	}
}
}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> v;
	for (int i = 0; i < n; ++i)
	{int f;
		cin>>f;
		v.push_back(k);
		/* code */
	}
	sort(v.begin(),v.end());

	if(v[k-1]!=v[k])
	{
        cout<<v[k-1]+1<<"\n";
	}
	else
	{
		cout<<"-1"<<"\n";
	}

}


#include <bits/stdc++.h>
using namespace std;

int main(){

    vector<int> m;
    int n, k;
    cin >> n >> k;

    for(int f = 0; f < n; f++){
        int r; cin >> r; m.push_back(r);
    }

    sort(m.begin(), m.end());
    if(k == 0 || m.size() == 0){
        cout << -1 << endl; return 0;
    }if(m.size() == 1 && k == 1){
        cout << m[0] << endl; return 0;
    }if(k == n){
        cout << m[n - 1] << endl; return 0;
    }

    int roof = m[k - 1];
    if(m[k - 2] == roof || m[k] == roof){
        if(m[k - 2] == roof && m[k] != roof && m[k] != roof + 1){
            cout << roof + 1 << endl;
        }
        else {cout << -1 << endl;}
    }else{
        if(roof == 0){
            cout << -1 << endl;
            return 0;
        }
        cout << roof << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){

    vector<int> m;
    int n, k;
    cin >> n >> k;

    for(int f = 0; f < n; f++){
        int r; cin >> r; m.push_back(r);
    }

    sort(m.begin(), m.end());
    if(k == 0 || m.size() == 0){
        cout << -1 << endl; return 0;
    }if(m.size() == 1 && k == 1){
        cout << m[0] << endl; return 0;
    }

    int roof = m[k - 1];
    if(m[k - 2] == roof || m[k] == roof){
        cout << -1 << endl;
    }else{
        if(roof == 0){
            cout << -1 << endl;
            return 0;
        }
        cout << roof << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define FOR(n) for(int i=0;i<n;++i)
#define FOK(k,n) for(int i=k;i<n;++i)
#define debVar(x) cout<<#x<<" = "<<x<<"\n";
#define debArr(arr,n) FOR(i,n){cout<<arr[i]<<" ";}cout<<endl;
#define space() cout<<endl;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef map<string,int> msi;

int main(){
    /*
    int n,k; cin>>n>>k;
    vi arr(n,0);
    mii m;
    foR(i,n){
        cin>>arr[i]; ++m[arr[i]];
    }
    sort(arr.begin(), arr.end());
    bool found=false;
    //debArr(arr,n);
    if(k==1){
        cout<<arr[0]<<endl;
        return 0;
    }else if(k==0){
        cout<<-1<<endl;
        return 0;
    }

    int sum=0;
    for(auto x=m.begin();x!=m.end();++x){
        //debVar(x->first);
        sum+=x->second;
        if(sum>=k){
            if(arr[sum-1]==arr[sum-2]){
                cout<<-1<<endl;
                return 0;
            }
            cout<<x->first<<endl;
            found=true;
            break;
        }
    }

    if(!found) cout<<-1<<endl;
    */

    int n,k;cin>>n>>k;
    int arr[n];
    FOR(n)cin>>arr[i];
    sort(arr,arr+n);
    if(k==0){
        cout<<(arr[0]==1?-1:1)<<endl;
        return 0;
    } // if n==1 and k==0 and the first element is 1, no x will be BOTH
      //between 1 and 10^9 and also 0 to prevent 1 from counting

      //if n==1 and k==0 and the first element is not 1, then only one x will
      //account for the case that 0 elements of said array are less than or equal
      //to x.
    int count=1;
    if(arr[k]==arr[k-1])cout<<-1<<endl;
    else cout<<arr[k-1]<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){

    vector<int> m;
    int n, k;
    cin >> n >> k;

    for(int f = 0; f < n; f++){
        int r; cin >> r; m.push_back(r);
    }

    sort(m.begin(), m.end());
    if(k == 0 || m.size() == 0){
        cout << -1 << endl; return 0;
    }if(m.size() == 1 && k == 1){
        cout << m[0] << endl; return 0;
    }

    int roof = m[k - 1];
    if(m[k - 2] == roof || m[k] == roof){
        cout << -1 << endl;
    }else{
        cout << roof << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define foR(i,n) for(int i=0;i<n;++i)
#define foK(i,k,n) for(i=k;i<n;++i)
#define debVar(x) cout<<#x<<" = "<<x<<"\n";
#define debArr(arr,n) foR(i,n){cout<<arr[i]<<" ";}cout<<endl;
#define space() cout<<endl;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef map<string,int> msi;

int main(){

    int n,k; cin>>n>>k;
    vi arr(n,0);
    mii m;
    foR(i,n){
        cin>>arr[i]; ++m[arr[i]];
    }
    sort(arr.begin(), arr.end());
    bool found=false;
    //debArr(arr,n);
    if(k<=1){
        cout<<arr[0]<<endl;
    }

    int sum=0;
    for(auto x=m.begin();x!=m.end();++x){
        //debVar(x->first);
        sum+=x->second;
        if(sum>=k){
            if(arr[sum-1]==arr[sum-2]){
                cout<<-1<<endl;
                return 0;
            }
            cout<<x->first<<endl;
            found=true;
            break;
        }
        //debVar(sum);
    }

    if(!found) cout<<-1<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define FOR(n) for(int i=0;i<n;++i)
#define FOK(k,n) for(int i=k;i<n;++i)
#define debVar(x) cout<<#x<<" = "<<x<<"\n";
#define debArr(arr,n) FOR(i,n){cout<<arr[i]<<" ";}cout<<endl;
#define space() cout<<endl;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef map<string,int> msi;

int main(){
    /*
    int n,k; cin>>n>>k;
    vi arr(n,0);
    mii m;
    foR(i,n){
        cin>>arr[i]; ++m[arr[i]];
    }
    sort(arr.begin(), arr.end());
    bool found=false;
    //debArr(arr,n);
    if(k==1){
        cout<<arr[0]<<endl;
        return 0;
    }else if(k==0){
        cout<<-1<<endl;
        return 0;
    }

    int sum=0;
    for(auto x=m.begin();x!=m.end();++x){
        //debVar(x->first);
        sum+=x->second;
        if(sum>=k){
            if(arr[sum-1]==arr[sum-2]){
                cout<<-1<<endl;
                return 0;
            }
            cout<<x->first<<endl;
            found=true;
            break;
        }
    }

    if(!found) cout<<-1<<endl;
    */

    int n,k;cin>>n>>k;
    int arr[n];
    FOR(n)cin>>arr[i];
    sort(arr,arr+n);
    if(k==0){
        cout<<(arr[0]==1?-1:1)<<endl;
        return 0;
    } // if n==1 and k==0 and the first element is 1, no x will be BOTH
      //between 1 and 10^9 and also 0 to prevent 1 from counting

      //if n==1 and k==0 and the first element is not 1, then only one x will
      //account for the case that 0 elements of said array are less than or equal
      //to x.
    int count=1;
    if(arr[k]==arr[k-1]||arr[k-1]==arr[k-2]) cout<<-1<<endl;
    else cout<<arr[k-1]<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){

    vector<int> m;
    int n, k;
    cin >> n >> k;

    for(int f = 0; f < n; f++){
        int r; cin >> r; m.push_back(r);
    }

    sort(m.begin(), m.end());
    if(k == 0 || m.size() == 0){
        cout << -1 << endl; return 0;
    }if(m.size() == 1 && k == 1){
        cout << m[0] << endl; return 0;
    }

    int roof = m[k - 1];
    if(m[k - 2] == roof || m[k] == roof){
        cout << -1 << endl;
    }else{
        if(root == 0){
            cout << -1 << endl;
            return 0;
        }
        cout << roof << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define foR(i,n) for(int i=0;i<n;++i)
#define foK(i,k,n) for(i=k;i<n;++i)
#define debVar(x) cout<<#x<<" = "<<x<<"\n";
#define debArr(arr,n) foR(i,n){cout<<arr[i]<<" ";}cout<<endl;
#define space() cout<<endl;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef map<string,int> msi;

int main(){

    int n,k; cin>>n>>k;
    vi arr(n,0);
    mii m;
    foR(i,n){
        cin>>arr[i]; ++m[arr[i]];
    }
    sort(arr.begin(), arr.end());
    bool found=false;
    //debArr(arr,n);
    if(k==1){
        cout<<arr[0]<<endl;
        return 0;
    }else if(k==0){
        cout<<-1<<endl;
        return 0;
    }

    int sum=0;
    for(auto x=m.begin();x!=m.end();++x){
        //debVar(x->first);
        sum+=x->second;
        if(sum>=k){
            if(arr[sum-1]==arr[sum-2]){
                cout<<-1<<endl;
                return 0;
            }
            cout<<x->first<<endl;
            found=true;
            break;
        }
        //debVar(sum);
    }

    if(!found) cout<<-1<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define foR(i,n) for(int i=0;i<n;++i)
#define foK(i,k,n) for(i=k;i<n;++i)
#define debVar(x) cout<<#x<<" = "<<x<<"\n";
#define debArr(arr,n) foR(i,n){cout<<arr[i]<<" ";}cout<<endl;
#define space() cout<<endl;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef map<string,int> msi;

int main(){

    int n,k; cin>>n>>k;
    vi arr(n,0);
    mii m;
    foR(i,n){
        cin>>arr[i]; ++m[arr[i]];
    }
    sort(arr.begin(), arr.end());
    bool found=false;
    //debArr(arr,n);

    int sum=0;
    for(auto x=m.begin();x!=m.end();++x){
        //debVar(x->first);
        sum+=x->second;
        if(sum>=k){
            if(arr[sum-1]==arr[sum-2]){
                cout<<-1<<endl;
                return 0;
            }
            cout<<x->first<<endl;
            found=true;
            break;
        }
        //debVar(sum);
    }

    if(!found) cout<<-1<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){

    vector<int> m;
    int n, k;
    cin >> n >> k;

    for(int f = 0; f < n; f++){
        int r; cin >> r; m.push_back(r);
    }

    sort(m.begin(), m.end());
    if(k == 0 || m.size() == 0){
        cout << -1 << endl; return 0;
    }if(m.size() == 1 && k == 1){
        if(m[0] == 0){
            cout << -1 << endl;
            return 0;
        }
        cout << m[0] << endl; return 0;
    }if(k == n){
        cout << m[n - 1] << endl; return 0;
    }

    int roof = m[k - 1];
    if(m[k - 2] == roof || m[k] == roof){
        if(m[k - 2] == roof && m[k] != roof && m[k] != roof + 1){
            cout << roof + 1 << endl;
        }
        else {cout << -1 << endl;}
    }else{
        if(roof == 0){
            cout << -1 << endl;
            return 0;
        }
        cout << roof << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){

    vector<int> m;
    int n, k;
    cin >> n >> k;

    for(int f = 0; f < n; f++){
        int r; cin >> r; m.push_back(r);
    }

    sort(m.begin(), m.end());
    if(k == 0 || m.size() == 0){
        cout << -1 << endl; return 0;
    }if(m.size() == 1 && k == 1){
        cout << m[0] << endl; return 0;
    }if(k == n){
        cout << m[n - 1] << endl; return 0;
    }

    int roof = m[k - 1];
    if(m[k - 2] == roof || m[k] == roof){
        cout << -1 << endl;
    }else{
        if(roof == 0){
            cout << -1 << endl;
            return 0;
        }
        cout << roof << endl;
    }

    return 0;
}


//#include<bits/stdc++.h>

#include<iostream>
#include <algorithm>
using namespace std;
int main(){

	int n, k;
	const int _10pow9 = 1000000000;
	cin>>n>>k;
	int ai[n];
	for(int i=0;i<n;i++){
		cin>>ai[i];
	}
	sort(ai, ai+n);

	if(k==0){
		if(ai[0]==1)
			cout<<-1<<endl;
		else
			cout<<1<<endl;
	}else if(k==n && ai[k-1]<=_10pow9){
		cout<<ai[k-1]<<endl;
	}else if(ai[k-1]>_10pow9){
		cout<<"-1"<<endl;
	}else if(ai[k-1]==ai[k]){
		cout<<"-1"<<endl;
	}else{
		cout<<ai[k-1]<<endl;
	}

	return 0;
}


//#include<bits/stdc++.h>

#include<iostream>
#include <algorithm>
using namespace std;
int main(){

	int n, k;
	const int _10pow9 = 1000000000;
	cin>>n>>k;
	int ai[n];
	for(int i=0;i<n;i++){
		cin>>ai[i];
	}
	sort(ai, ai+n);

	if(k==n && ai[k-1]<=_10pow9){
		cout<<ai[k-1]<<endl;
	}else if(ai[k-1]>_10pow9){
		cout<<"-1"<<endl;
	}else if(ai[k-1]==ai[k]){
		cout<<"-1"<<endl;
	}else{
		cout<<ai[k-1]<<endl;
	}

	return 0;
}


//#include<bits/stdc++.h>

#include<iostream>
#include <algorithm>
using namespace std;
int main(){

	int n, k;
	cin>>n>>k;
	int ai[n];
	for(int i=0;i<n;i++){
		cin>>ai[i];
	}
	sort(ai, ai+n);

	if(k==n && ai[k-1]<1000000000){
		cout<<(ai[k-1]+1)<<endl;
	}else if(ai[k-1]>=1000000000){
		cout<<"-1"<<endl;
	}else if(k==0){
		cout<<"-1"<<endl;
	}else if(ai[k-1]==ai[k]){
		cout<<"-1"<<endl;
	}else{
		cout<<(ai[k-1]+1)<<endl;
	}

	return 0;
}


//#include<bits/stdc++.h>

#include<iostream>
#include <algorithm>
using namespace std;
int main(){

	int n, k;
	const int _10pow9 = 1000000000;
	cin>>n>>k;
	int ai[n];
	for(int i=0;i<n;i++){
		cin>>ai[i];
	}
	sort(ai, ai+n);

	if(k==n && ai[k-1]<=_10pow9){
		cout<<ai[k-1]<<endl;
	}else if(ai[k-1]>_10pow9){
		cout<<"-1"<<endl;
	}else if(k==0){
		cout<<-1<<endl;
	}else if(ai[k-1]==ai[k]){
		cout<<"-1"<<endl;
	}else{
		cout<<ai[k-1]<<endl;
	}

	return 0;
}


//#include<bits/stdc++.h>

#include<iostream>
#include <algorithm>
using namespace std;
int main(){

	int n, k;
	const int _10pow9 = 1000000000;
	cin>>n>>k;
	int ai[n];
	for(int i=0;i<n;i++){
		cin>>ai[i];
	}
	sort(ai, ai+n);

	if(k==n && ai[k-1]<=_10pow9){
		cout<<ai[k-1]<<endl;
	}else if(ai[k-1]>_10pow9){
		cout<<"-1"<<endl;
	}else if(k==0){
		cout<<"1"<<endl;
	}else if(ai[k-1]==ai[k]){
		cout<<"-1"<<endl;
	}else{
		cout<<ai[k-1]<<endl;
	}

	return 0;
}


//#include<bits/stdc++.h>

#include<iostream>
#include <algorithm>
using namespace std;
int main(){

	int n, k;
	cin>>n>>k;
	int ai[n];
	for(int i=0;i<n;i++){
		cin>>ai[i];
	}
	sort(ai, ai+n);

	if(k==n && ai[k-1]<1000000000){
		cout<<(ai[k-1]+1)<<endl;
	}else if(ai[k-1]>=1000000000){
		cout<<"-1"<<endl;
	}else if(k==0){
		cout<<"0"<<endl;
	}else if(ai[k-1]==ai[k]){
		cout<<"-1"<<endl;
	}else{
		cout<<(ai[k-1]+1)<<endl;
	}

	return 0;
}


//#include<bits/stdc++.h>

#include<iostream>
#include <algorithm>
using namespace std;
int main(){

	int n, k;
	const int _10pow9 = 1000000000;
	cin>>n>>k;
	int ai[n];
	for(int i=0;i<n;i++){
		cin>>ai[i];
	}
	sort(ai, ai+n);

	if(k==n && ai[k-1]<=_10pow9){
		cout<<ai[k-1]<<endl;
	}else if(ai[k-1]>_10pow9){
		cout<<"-1"<<endl;
	}else if(k==0){
		if(ai[0]==1)
			cout<<-1<<endl;
		else
			cout<<1<<endl;
	}else if(ai[k-1]==ai[k]){
		cout<<"-1"<<endl;
	}else{
		cout<<ai[k-1]<<endl;
	}

	return 0;
}


//#include<bits/stdc++.h>

#include<iostream>
#include <algorithm>
using namespace std;
int main(){

	int n, k;
	const int _10pow9 = 1000000000;
	cin>>n>>k;
	int ai[n];
	for(int i=0;i<n;i++){
		cin>>ai[i];
	}
	sort(ai, ai+n);

	if(k==n && ai[k-1]<=_10pow9){
		cout<<ai[k-1]<<endl;
	}else if(ai[k-1]>_10pow9){
		cout<<"-1"<<endl;
	}else if(k==0){
		cout<<ai[0]-1<<endl;
	}else if(ai[k-1]==ai[k]){
		cout<<"-1"<<endl;
	}else{
		cout<<ai[k-1]<<endl;
	}

	return 0;
}


//#include<bits/stdc++.h>

#include<iostream>
#include <algorithm>
using namespace std;
int main(){

	int n, k;
	cin>>n>>k;
	int ai[n];
	for(int i=0;i<n;i++){
		cin>>ai[i];
	}
	sort(ai, ai+n);

	if(k==n && ai[k-1]<1000000000){
		cout<<ai[k-1]+1;
	}else if(ai[k-1]>=1000000000){
		cout<<"-1";
	}else if(ai[k-1]==ai[k]){
		cout<<"-1";
	}else{
		cout<<ai[k-1]+1;
	}

	return 0;
}


//#include<bits/stdc++.h>

#include<iostream>
#include <algorithm>
using namespace std;
int main(){

	int n, k;
	const int _10pow9 = 1000000000;
	cin>>n>>k;
	int ai[n];
	for(int i=0;i<n;i++){
		cin>>ai[i];
	}
	sort(ai, ai+n);

	if(k==n && ai[k-1]<=_10pow9){
		cout<<ai[k-1]<<endl;
	}else if(ai[k-1]>_10pow9){
		cout<<"-1"<<endl;
	}else if(k==0){
		cout<<"-1"<<endl;
	}else{
		cout<<ai[k-1]<<endl;
	}

	return 0;
}


//#include<bits/stdc++.h>

#include<iostream>
#include <algorithm>
using namespace std;
int main(){

	int n, k;
	cin>>n>>k;
	int ai[n];
	for(int i=0;i<n;i++){
		cin>>ai[i];
	}
	sort(ai, ai+n);

	if(k==n && ai[k-1]<=1000000000){
		cout<<(ai[k-1]+1)<<endl;
	}else if(ai[k-1]>1000000000){
		cout<<"-1"<<endl;
	}else if(k==0){
		cout<<"-1"<<endl;
	}else if(ai[k-1]==ai[k]){
		cout<<"-1"<<endl;
	}else{
		cout<<(ai[k-1]+1)<<endl;
	}

	return 0;
}


//#include<bits/stdc++.h>

#include<iostream>
#include <algorithm>
using namespace std;
int main(){

	int n, k;
	const int _10pow9 = 1000000000;
	cin>>n>>k;
	int ai[n];
	for(int i=0;i<n;i++){
		cin>>ai[i];
	}
	sort(ai, ai+n);

	if(k==n && ai[k-1]<=_10pow9){
		cout<<ai[k-1]+1000000000<<endl;
	}else if(ai[k-1]>_10pow9){
		cout<<"-1"<<endl;
	}else if(k==0){
		cout<<"-1"<<endl;
	}else if(ai[k-1]==ai[k]){
		cout<<"-1"<<endl;
	}else{
		cout<<ai[k-1]<<endl;
	}

	return 0;
}


//#include<bits/stdc++.h>

#include<iostream>
#include <algorithm>
using namespace std;
int main(){

	int n, k;
	const int _10pow9 = 1000000000;
	cin>>n>>k;
	int ai[n];
	for(int i=0;i<n;i++){
		cin>>ai[i];
	}
	sort(ai, ai+n);

	if(k==n && ai[k-1]<=_10pow9){
		cout<<ai[k-1]<<endl;
	}else if(ai[k-1]==ai[k]){
		cout<<"-1"<<endl;
	}else{
		cout<<ai[k-1]<<endl;
	}

	return 0;
}


//#include<bits/stdc++.h>

#include<iostream>
#include <algorithm>
using namespace std;
int main(){

	int n, k;
	cin>>n>>k;
	int ai[n];
	for(int i=0;i<n;i++){
		cin>>ai[i];
	}
	sort(ai, ai+n);

	if(k==n && ai[k-1]<=1000000000){
		cout<<1000000000<<endl;
	}else if(ai[k-1]>1000000000){
		cout<<"-1"<<endl;
	}else if(k==0){
		cout<<"-1"<<endl;
	}else if(ai[k-1]==ai[k]){
		cout<<"-1"<<endl;
	}else{
		cout<<(ai[k-1])<<endl;
	}

	return 0;
}


//#include<bits/stdc++.h>

#include<iostream>
#include <algorithm>
using namespace std;
int main(){

	int n, k;
	const int _10pow9 = 1000000000;
	cin>>n>>k;
	int ai[n];
	for(int i=0;i<n;i++){
		cin>>ai[i];
	}
	sort(ai, ai+n);

	if(k==n && ai[k-1]<=_10pow9){
		cout<<ai[k-1]<<endl;
	}else if(ai[k-1]>_10pow9){
		cout<<"-1"<<endl;
	}else if(k==0){
		cout<<"-1"<<endl;
	}else if(ai[k-1]==ai[k]){
		cout<<"-1"<<endl;
	}else{
		cout<<ai[k-1]<<endl;
	}

	return 0;
}


//#include<bits/stdc++.h>

#include<iostream>
#include <algorithm>
using namespace std;
int main(){

	int n, k;
	const int _10pow9 = 1000000000;
	cin>>n>>k;
	int ai[n];
	for(int i=0;i<n;i++){
		cin>>ai[i];
	}
	sort(ai, ai+n);

	if(k==n && ai[k-1]<=_10pow9){
		cout<<_10pow9<<endl;
	}else if(ai[k-1]>_10pow9){
		cout<<"-1"<<endl;
	}else if(k==0){
		cout<<"-1"<<endl;
	}else if(ai[k-1]==ai[k]){
		cout<<"-1"<<endl;
	}else{
		cout<<ai[k-1]<<endl;
	}

	return 0;
}


//#include<bits/stdc++.h>

#include<iostream>
#include <algorithm>
using namespace std;
int main(){

	int n, k;
	cin>>n>>k;
	int ai[n];
	for(int i=0;i<n;i++){
		cin>>ai[i];
	}
	sort(ai, ai+n);

	if(k==n && ai[k-1]<=1000000000){
		cout<<1000000000<<endl;
	}else if(ai[k-1]>1000000000){
		cout<<"-1"<<endl;
	}else if(k==0){
		cout<<"-1"<<endl;
	}else if(ai[k-1]==ai[k]){
		cout<<"-1"<<endl;
	}else{
		cout<<(ai[k-1]+1)<<endl;
	}

	return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>

//#define debug
#ifdef debug
std::ifstream cin("test.txt");
#endif // debug
#ifndef debug
using std::cin;
#endif // debug

using std::cout;
using std::endl;

int main(){
    int n, k;
    cin >> n >> k;
    int arr[n];
    for(int i = 0; i != n; ++i)
        cin >> arr[i];

    std::sort(arr, arr + n);

    if(k == 0 && arr[0] == 1)
        cout << "-1";
    else if(k ==0 && arr[0] > 1)
        cout << "1";

    if(k == n)
        cout << arr[k - 1];
    else if(arr[k - 1] == arr[k])
        cout << "-1";
        else
            cout << arr[k - 1];

    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#define debug
#ifdef debug
std::ifstream cin("test.txt");
#endif // debug
#ifndef debug
using std::cin;
#endif // debug

using std::cout;
using std::endl;

int main(){
    int n, k;
    cin >> n >> k;
    int arr[n];
    for(int i = 0; i != n; ++i){
        cin >> arr[i];
    }
    std::sort(arr, arr + n);
    if(k == n)
        cout << arr[k - 1] + 1;
    else{
        if(arr[k] - arr[k - 1] <= 1)
            cout << "-1";
        else
            cout << arr[k - 1];
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
//#define debug
#ifdef debug
std::ifstream cin("test.txt");
#endif // debug
#ifndef debug
using std::cin;
#endif // debug

using std::cout;
using std::endl;

int main(){
    int n, k;
    cin >> n >> k;
    int arr[n];
    for(int i = 0; i != n; ++i){
        cin >> arr[i];
    }
    std::sort(arr, arr + n);
    if(arr[k] - arr[k - 1] <= 1)
        cout << "-1";
    else if(arr[k] - arr[k - 1] > 1)
        cout << arr[k - 1] + 1;
    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
//#define debug
#ifdef debug
std::ifstream cin("test.txt");
#endif // debug
#ifndef debug
using std::cin;
#endif // debug

using std::cout;
using std::endl;

int main(){
    int n, k;
    cin >> n >> k;
    int arr[n];
    for(int i = 0; i != n; ++i){
        cin >> arr[i];
    }
    std::sort(arr, arr + n);
    if(k == n)
        cout << arr[k - 1] + 1;
    else if(k == 0 && arr[0] > 1)
        cout << arr[0] - 1;
    else{
        if(arr[k] - arr[k - 1] <= 1)
            cout << "-1";
        else
            cout << arr[k - 1];
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
//#define debug
#ifdef debug
std::ifstream cin("test.txt");
#endif // debug
#ifndef debug
using std::cin;
#endif // debug

using std::cout;
using std::endl;

int main(){
    int n, k;
    cin >> n >> k;
    int arr[n];
    for(int i = 0; i != n; ++i){
        cin >> arr[i];
    }
    std::sort(arr, arr + n);
    if(k == n)
        cout << arr[k - 1] + 1;
    else{
        if(arr[k] - arr[k - 1] <= 1)
            cout << "-1";
        else
            cout << arr[k - 1];
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
//#define debug
#ifdef debug
std::ifstream cin("test.txt");
#endif // debug
#ifndef debug
using std::cin;
#endif // debug

using std::cout;
using std::endl;

int main(){
    int n, k;
    cin >> n >> k;
    int arr[n];
    for(int i = 0; i != n; ++i){
        cin >> arr[i];
    }
    std::sort(arr, arr + n);
    if(k == n)
        cout << arr[k - 1] + 1;
    else{
        if(arr[k] - arr[k - 1] <= 1)
            cout << "-1";
        else
            cout << arr[k - 1] + 1;
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
//#define debug
#ifdef debug
std::ifstream cin("test.txt");
#endif // debug
#ifndef debug
using std::cin;
#endif // debug

using std::cout;
using std::endl;

int main(){
    int n, k;
    cin >> n >> k;
    int arr[n];
    for(int i = 0; i != n; ++i){
        cin >> arr[i];
    }
    std::sort(arr, arr + n);
    if(k == n)
        cout << arr[k - 1] + 1;
    else{
        if(arr[k] - arr[k - 1] == 0)
            cout << "-1";
        else
            cout << arr[k - 1] + 1;
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
//#define debug
#ifdef debug
std::ifstream cin("test.txt");
#endif // debug
#ifndef debug
using std::cin;
#endif // debug

using std::cout;
using std::endl;

int main(){
    int n, k;
    cin >> n >> k;
    int arr[n];
    for(int i = 0; i != n; ++i){
        cin >> arr[i];
    }
    std::sort(arr, arr + n);
    if(k == n)
        cout << arr[k - 1];
    else if(k == 0 && arr[0] > 1)
        cout << arr[0] - 1;
    else{
        if(arr[k] - arr[k - 1] <= 1)
            cout << "-1";
        else
            cout << arr[k - 1];
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>

//#define debug
#ifdef debug
std::ifstream cin("test.txt");
#endif // debug
#ifndef debug
using std::cin;
#endif // debug

using std::cout;
using std::endl;

int main(){
    int n, k;
    cin >> n >> k;
    int arr[n];
    for(int i = 0; i != n; ++i)
        cin >> arr[i];

    std::sort(arr, arr + n);

    if(k == 0 && arr[0] == 1)
        cout << "-1";
    else if(k ==0 && arr[0] > 1)
        cout << "1";
    else{
        if(k == n)
            cout << arr[k - 1];
        else if(arr[k - 1] == arr[k])
            cout << "-1";
            else
                cout << arr[k - 1];
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
//#define debug
#ifdef debug
std::ifstream cin("test.txt");
#endif // debug
#ifndef debug
using std::cin;
#endif // debug

using std::cout;
using std::endl;

int main(){
    int n, k;
    cin >> n >> k;
    int arr[n];
    for(int i = 0; i != n; ++i){
        cin >> arr[i];
    }
    std::sort(arr, arr + n);
    if(arr[k] - arr[k - 1] <= 0)
        cout << "-1";
    else if(arr[k] - arr[k - 1] > 0)
        cout << arr[k - 1] + 1;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int maxn=2000010;
ll n,k,ans;
ll a[maxn];
int main()
{
	while(cin>>n>>k)
	{
		int i,j;
		memset(a,-1,sizeof(a));
		for(i=1;i<=n;i++)
		{
			scanf("%I64d",&a[i]);
		}
		sort(a+1,a+n+1);
		if(k<n && a[k]==a[k+1]) ans=-1;
		else if(k==0 && a[0]==1) ans=-1;
    	else if(k==0 && a[0]!=1) ans=a[0]-1;
		else ans=a[k];
		cout<<ans<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int maxn=2000010;
ll n,k,ans;
ll a[maxn];
int main()
{
	while(cin>>n>>k)
	{
		int i,j;
		memset(a,-1,sizeof(a));
		for(i=1;i<=n;i++)
		{
			scanf("%I64d",&a[i]);
		}
		sort(a+1,a+n+1);
		if(k<n && a[k]==a[k+1]) ans=-1;
		else if(k==0 && a[1]==1) ans=-1;
    	else if(k==0 && a[1]!=1) ans=a[1]-1;
		else ans=a[k];
		cout<<ans<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int maxn=2000010;
ll n,k,ans;
ll a[maxn];
int main()
{
	while(cin>>n>>k)
	{
		int i,j;
		memset(a,-1,sizeof(a));
		for(i=1;i<=n;i++)
		{
			scanf("%I64d",&a[i]);
		}
		sort(a+1,a+n+1);
		if(k==0||(k<n&&a[k]==a[k+1]))
		ans=-1;
		else
		ans=a[k];
		cout<<ans<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int maxn=300000;
int n,k,ans;
int a[maxn];
int main()
{
	while(cin>>n>>k)
	{
		int i,j;
		for(i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
		}
		sort(a+1,a+n+1);
		if(k==n)
		ans=a[k];
		else if(a[k]==a[k+1]||k==0)
		ans=-1;
		else if(a[k]==a[k+1]-1)
		ans=a[k];
		else
		ans=a[k]+1;
		cout<<ans<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int maxn=300000;
int n,k,ans;
int a[maxn];
int main()
{
	while(cin>>n>>k)
	{
		int i,j;
		memset(a,-1,sizeof(a));
		for(i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
		}
		sort(a+1,a+n+1);
		if(k==0||(k<n&&a[k]==a[k+1]))
		ans=-1;
		else
		ans=a[k];
		cout<<ans<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int maxn=300000;
int n,k,ans;
int a[maxn];
int main()
{
	while(cin>>n>>k)
	{
		int i,j;
		for(i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
		}
		sort(a+1,a+n+1);
		if(k==n)
		ans=a[k];
		else if(a[k]==a[k+1]||k==0)
		ans=-1;
		else
		ans=a[k];
		cout<<ans<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int maxn=300000;
int n,k,ans;
int a[maxn];
int main()
{
	while(cin>>n>>k)
	{
		int i,j;
		memset(a,-1,sizeof(a));
		for(i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
		}
		sort(a+1,a+n+1);
		if(k==n)
		ans=a[k];
		else if(k==0||a[k]==a[k+1])
		ans=-1;
		else
		ans=a[k+1]-1;
		cout<<ans<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int maxn=300000;
int n,k,ans;
int a[maxn];
int main()
{
	while(cin>>n>>k)
	{
		int i,j;
		for(i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
		}
		sort(a+1,a+n+1);
		if(a[k]==a[k+1]||k==0)
		ans=-1;
		else if(a[k]==a[k+1]-1)
		ans=a[k];
		else
		ans=a[k]+1;
		cout<<ans<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int maxn=300000;
int n,k,ans;
int a[maxn];
int main()
{
	while(cin>>n>>k)
	{
		int i,j;
		for(i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
		}
		sort(a,a+n);
		if(a[k-1]==a[k])
		ans=-1;
		else if(a[k-1]==a[k]-1)
		ans=a[k-1];
		else
		ans=a[k-1]+1;
		cout<<ans<<endl;
	}
	return 0;
}


//Code by a weak man who named tarjin, and he hopes the code can get more points.
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int NR=2e5;
int n,k;
int a[NR+5];
int main(void)
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	if(k==0)
	{
		if(a[1]==1)
			printf("-1\n");
		else
			printf("%d\n",a[1]-1);
		return 0;
	}
	if(k==n)
	{
		printf("%d\n",a[n]);
		return 0;
	}
	if(a[k]==a[k+1])
	{
		printf("-1\n");
		return 0;
	}
	printf("%d\n",a[k]);
	return 0;
}


#include<iostream>
#include<set>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn=2e5+10;
const int INF = 0x3f3f3f3f;
const int mod=998244353;
typedef long long ll;
int main(){
int n,m;
int a[maxn];
cin>>n>>m;
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
int i=upper_bound(a,a+n,a[m-1])-a;
if(i==m) cout<<a[i]-1<<endl;
else cout<<-1<<endl;
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[1000001];
int main()
{
	int n,k;
	cin>>n>>k;
	long long max=0,min=10e+9;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(max<a[i]) max=a[i];
		else if(min>a[i]) min=a[i];
	}
	int sum=0,i;
	for(i=min;i<=max;i++)
	{
		sum=0;
		for(int j=1;j<=n;j++)
			if(a[j]<=i) sum++;
		if(sum==k) break;
	}
	if(sum!=k) cout<<-1;
	else cout<<i;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,k,a[200001];
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;++i) cin>>a[i];
    sort(a+1,a+n+1);
    if(a[k+1]==a[k]) cout<<-1;
    else cout<<a[k];
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
int  n, k;
int  a[maxn];
int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) cin >> a[i];
	sort(a + 1, a + 1 + n);
	if (k == 0) {
		if(a[1]!=1) cout << a[1] - 1 << endl;
		else cout << -1 << endl;
	}
	else if (n == 1) cout << a[1] << endl;
	else if (k == n) cout << a[n] << endl;
	else if (a[k + 1] > a[k] && a[k] >= 1 && a[k] <= 1e9) cout << a[k] << endl;
	else cout << -1 << endl;
	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<string.h>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
typedef unsigned long long ull;
typedef  long long ll;
#define INF  1e9
#define M 2000000
#define N  210100
const ll mod = 1e9+7;
ll n,a[N],k,flag,x;
map<ll,ll>mp;
int main(void){
	scanf("%lld %lld",&n,&k);
	for(ll i = 1;i<= n;i++){
		scanf("%lld",&a[i]);
	}
	sort(a+1,a+n+1);
	if(k==0&&a[1]==1){
        cout<<"-1"<<endl;
        return 0;
    }
    else if(k==0){
        cout<<"1"<<endl;
        return 0;
    }

    if(a[k]==a[k+1])
	cout<<"-1"<<endl;
    else {
        cout<<a[k]<<endl;
        }
    return 0;
}


#include<bits/stdc++.h>//sososososo easy!
using namespace std;
int main() {
	int m, n;
	cin >> m >> n;
	vector<int> a(m);
	for (int i = 0; i < m; i++)
		cin >> a[i];
	sort(a.begin(), a.end());
	if (n == 0) {
		int ans = a[0] - 1;
		if (ans < 1)
			cout << -1 << endl;
		else
			cout << ans << endl;
	}
	else if (a[n - 1] == a[n])
		cout << -1 << endl;
	else
		cout << a[n - 1] << endl;
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
int n, k;
int a[1000005];
int main()
{
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	sort(a + 1, a + n + 1);
	if (k == 0 && a[1] == 1)
	{
		cout << "-1" << endl;
		return 0;
	}
	else if (k == 0)
	{
		cout << "1" << endl;
		return 0;
	}

	if (a[k] == a[k + 1]||a[k]+1==a[k+1])cout << "-1" << endl;
	else
	{
		cout << a[k] << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[1000001];
int main()
{
	int n,k;
	cin>>n>>k;
	long long max=0,min=10e+9;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(max<a[i]) max=a[i];
		else if(min>a[i]) min=a[i];
	}
	int sum=0,i;
	for(i=min;i<=max;i++)
	{
		sum=0;
		for(int j=1;j<=n;j++)
		{
			if(a[j]<=i) sum++;
		}
		if(sum==k) break;
	}
	if(sum!=k) cout<<-1;
	else cout<<i;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[2000005],n,k,x;
int main(){
	cin>>n>>k;
	memset(a,128,sizeof(a));
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1);
	if(k==0)
	{
		if(a[1]==1)
			cout<<-1;
		else
			cout<<1;
		return 0;
	}
	if(a[k-1]==a[k]||a[k+1]==a[k])
	{
		cout<<-1;
		return 0;
	}
	if(a[k]<=1000000000)
		cout<<a[k];//kk
	else
		cout<<1000000000;
	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<string.h>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
typedef unsigned long long ull;
typedef  long long ll;
#define INF  1e9
#define M 2000000
#define N  210100
const ll mod = 1e9+7;
ll n,a[N],k,flag,x;
int main(void){
	scanf("%lld %lld",&n,&k);
	for(ll i = 1;i<= n;i++){
		scanf("%lld",&a[i]);
	}
	sort(a+1,a+n+1);
	if(k==0&&a[1]==1){
        cout<<"-1"<<endl;
        return 0;
    }
    else if(k==0){
        cout<<"1"<<endl;
        return 0;
    }

    if(a[k]==a[k+1])
	cout<<"-1"<<endl;
    else {
        cout<<a[k]<<endl;
        }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int n, k, seq[200000], x;
int main(){
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++){
		scanf("%d", &seq[i]);
	}
	sort(seq, seq+n);

	if (k == 0){
		if (seq[0] == 1)
			printf("-1\n");
		else
			printf("%d\n", seq[0]-1);
	}

	if (k == n)
		printf("%d\n", seq[n-1]++);

	if (k < n && k != 0){
		x = seq[k-1]+1;
		if (seq[k] <= x)
			printf("-1\n");
		else
			printf("%d\n", x);
	}
}


#include <bits/stdc++.h>
using namespace std;

int n, k, seq[250000], x, cnt;

int main(){
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++)
		scanf("%d", &seq[i]);
	sort(seq, seq+n);
	if (k == 0)
		x = seq[0]-1;
	else
		x = seq[k-1]+1;
	for (int i = 0; i < n; i++){
		if (x >= seq[i])
			cnt++;
	}

	if (cnt == k && x > 0 && x <= 1000000000)
		printf("%d\n", x);
	else
		printf("-1\n");

	return 0;

}


#include <bits/stdc++.h>
using namespace std;

int n, k, seq[250000], x;

int main(){
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++){
		scanf("%d", &seq[i]);
	}
	sort(seq, seq+n);
	x = seq[k-1];
	x++;
	if (k == 0){
		x = seq[0];
		x--;
	}
	if (k < n && seq[k] <= x)
		printf("-1\n");
	else
		printf("%d\n", x);
}


#include <bits/stdc++.h>
using namespace std;

int n, k, seq[250000], x;

int main(){
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++){
		scanf("%d", &seq[i]);
	}
	sort(seq, seq+n);
	x = seq[k-1];
	x++;
	if (seq[k] <= x)
		printf("-1\n");
	else
		printf("%d\n", x);
}


#include <bits/stdc++.h>
using namespace std;

int n, k, seq[250000], x;

int main(){
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++){
		scanf("%d", &seq[i]);
	}
	sort(seq, seq+n);
	x = seq[k-1];
	x++;

	if (k == 0){
		x = seq[0];
		x--;
	}

	if (x < 1 || x > 1000000000 || k > n || seq[k] <= x)
		printf("-1\n");
	else
		printf("%d\n", x);
}


#include <bits/stdc++.h>
using namespace std;

int n, k, seq[250000], x, cnt;

int main(){
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++)
		scanf("%d", &seq[i]);
	sort(seq, seq+n);
	if (k == 0)
		x = seq[0]-1;
	else
		x = seq[k-1];
	for (int i = 0; i < n; i++){
		if (x >= seq[i])
			cnt++;
	}

	if (cnt == k && x > 0 && x <= 1000000000)
		printf("%d\n", x);
	else
		printf("-1\n");

	return 0;

}


#include <bits/stdc++.h>
using namespace std;

int n, k, seq[250000], x;

int main(){
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++){
		scanf("%d", &seq[i]);
	}
	sort(seq, seq+n);
	x = seq[k-1];
	x++;
	if (k < n && seq[k] <= x)
		printf("-1\n");
	else
		printf("%d\n", x);
}


#include <bits/stdc++.h>
using namespace std;

int n, k, x, seq[200000];

int main(){
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++){
		scanf("%d", &seq[i]);
	}
	sort(seq, seq+n);

	if (k == 0){
		x = seq[0];
		if (x == 1)
			printf("-1\n");
		else
			printf("%d\n", x-1);
	}

	else{
		x = seq[k-1]+1;
		if (k != n){
			if (x >= seq[k] || x < 1 || x > 99999999)
				printf("-1\n");
			else{
				printf("%d\n", x);
			}
		}
		else{
			if (x < 1 || x > 99999999){
				printf("-1\n");
			}
			else{
				printf("%d\n", x);
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int n, k, seq[200000], x;
int main(){
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++){
		scanf("%d", &seq[i]);
	}
	sort(seq, seq+n);

	if (k == 0){
		if (seq[0] <= 1)
			printf("-1\n");
		else
			printf("%d\n", seq[0]-1);
	}

	if (k == n)
		printf("%d\n", seq[n-1]++);

	if (k < n && k != 0){
		x = seq[k-1]+1;
		if (seq[k] <= x)
			printf("-1\n");
		else
			printf("%d\n", x);
	}
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 500005;

int n;

vector<int> g[N];
int ans[N];
int h[N];

int count_occ(const vector<int> &vec, int x) {
	return int(vec.rend() -
			lower_bound(vec.rbegin(), vec.rend(), x));
}

int prec_h(int u, int p) {
	h[u] = 1;
	for(int v : g[u]) if(v != p)
		h[u] = max(h[u], 1 + prec_h(v, u));
	return h[u];
}

vector<int> go(int u, int p) {
	auto mx = g[u];
	for(int &x : mx) x = h[x];
	sort(mx.rbegin(), mx.rend());
	int last = 0;
	for(int i = 0; i < (int)mx.size(); i++) {
		int j = i;
		while(j + 1 < (int)mx.size() and mx[j + 1] == mx[i]) j++;
		int len = j - i + 1;
		// printf(">u %d: mx %d len %d last %d\n", u, mx[i], j+1, last);
		ans[ 2 * mx[i] ] = max(ans[ 2 * mx[i] ], j + 1);
		ans[ 2 * mx[i]-1 ] = max(ans[ 2 * mx[i]-1 ], j + 1);
		ans[ 2 * mx[i]+1 ] = max(ans[ 2 * mx[i]+1 ], last + 1);
		last = j+1;
		i = j;
	}
	mx.push_back(0);
	int big = 0;
	for(int v : g[u]) {
		if(h[v] == mx[0]) big = v;
	}
	for(int v : g[u]) if(v != p) {
		if(v == big) h[u] = 1 + mx[1];
		else h[u] = 1 + mx[0];
		int oldv = h[v];
		h[v] = max(h[v], 1 + h[u]);
		auto vec = go(v, u);

		for(int i = 0; i < (int)vec.size(); i++) {
			int j = i;
			while(j + 1 < (int)vec.size() and vec[j + 1] == vec[i])
				j++;
			int cand = j + 1 - (h[u] >= vec[i]);
			cand += count_occ(mx, vec[i]) - (oldv >= vec[i]);
			// printf(">>u %d, v %d: vec %d len %d cand %d\n", u, v, vec[i], j+1+(h[u]<=vec[i]), cand);
			ans[2 * vec[i]] = max(ans[2*vec[i]], cand);
			i = j;
		}

		h[v] = oldv;
		h[u] = 1 + mx[0];
	}
	mx.pop_back();
	return mx;
}

int main() {

	scanf("%d", &n);

	for(int i = 1; i < n; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	prec_h(1, 1);
	for(int i = 1; i <= n; i++) ans[i] = 1;
	go(1, 1);

	for(int i = 1; i <= n; i++) {
		ans[1] = max(ans[1], 1 + int(g[i].size()));
	}

	for(int i = n - 2; i >= 1; i--) {
		ans[i] = max(ans[i], ans[i + 2]);
	}

	for(int i = 1; i <= n; i++) {
		printf("%d%c", ans[i], " \n"[i == n]);
	}

}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 500005;

int n;

vector<int> g[N];
int ans[N];
int h[N];

int count_occ(const vector<int> &vec, int x) {
	return int(vec.rend() -
			lower_bound(vec.rbegin(), vec.rend(), x));
}

int prec_h(int u, int p) {
	h[u] = 1;
	for(int v : g[u]) if(v != p)
		h[u] = max(h[u], 1 + prec_h(v, u));
	return h[u];
}

vector<int> go(int u, int p) {
	auto mx = g[u];
	for(int &x : mx) x = h[x];
	sort(mx.rbegin(), mx.rend());
	int last = 0;
	for(int i = 0; i < (int)mx.size(); i++) {
		int j = i;
		while(j + 1 < (int)mx.size() and mx[j + 1] == mx[i]) j++;
		int len = j - i + 1;
		// printf(">u %d: mx %d len %d last %d\n", u, mx[i], j+1, last);
		ans[ 2 * mx[i] ] = max(ans[ 2 * mx[i] ], j + 1);
		ans[ 2 * mx[i]-1 ] = max(ans[ 2 * mx[i]-1 ], j + 1);
		ans[ 2 * mx[i]+1 ] = max(ans[ 2 * mx[i]+1 ], last + 1);
		last = j+1;
		i = j;
	}
	mx.push_back(0);
	int big = 0;
	for(int v : g[u]) {
		if(h[v] == mx[0]) big = v;
	}
	for(int v : g[u]) if(v != p) {
		if(v == big) h[u] = 1 + mx[1];
		else h[u] = 1 + mx[0];
		int oldv = h[v];
		h[v] = max(h[v], 1 + h[u]);
		auto vec = go(v, u);

		for(int i = 0; i < (int)vec.size(); i++) {
			ans[2*vec[i]+2] = max(ans[2*vec[i]+2], i-(h[u]>vec[i])+count_occ(mx, vec[i]+1) - (oldv > vec[i]));
			int j = i;
			while(j + 1 < (int)vec.size() and vec[j + 1] == vec[i])
				j++;
			int cand = j + 1 - (h[u] >= vec[i]);
			cand += count_occ(mx, vec[i]) - (oldv >= vec[i]);
			// printf(">>u %d, v %d: vec %d len %d cand %d\n", u, v, vec[i], j+1+(h[u]<=vec[i]), cand);
			ans[2 * vec[i]] = max(ans[2*vec[i]], cand);
			i = j;
		}

		h[v] = oldv;
		h[u] = 1 + mx[0];
	}
	mx.pop_back();
	return mx;
}

int main() {

	scanf("%d", &n);

	for(int i = 1; i < n; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	prec_h(1, 1);
	for(int i = 1; i <= n; i++) ans[i] = 1;
	go(1, 1);

	for(int i = 1; i <= n; i++) {
		ans[1] = max(ans[1], 1 + int(g[i].size()));
	}

	for(int i = n - 2; i >= 1; i--) {
		ans[i] = max(ans[i], ans[i + 2]);
	}

	for(int i = 1; i <= n; i++) {
		printf("%d%c", ans[i], " \n"[i == n]);
	}

}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 500005;

int n;

vector<int> g[N];
int ans[N];
int h[N];

int count_occ(const vector<int> &vec, int x) {
	return int(vec.rend() -
			lower_bound(vec.rbegin(), vec.rend(), x));
}

int prec_h(int u, int p) {
	h[u] = 1;
	for(int v : g[u]) if(v != p)
		h[u] = max(h[u], 1 + prec_h(v, u));
	return h[u];
}

vector<int> go(int u, int p) {
	auto mx = g[u];
	for(int &x : mx) x = h[x];
	sort(mx.rbegin(), mx.rend());
	int last = 0;
	for(int i = 0; i < (int)mx.size(); i++) {
		int j = i;
		while(j + 1 < (int)mx.size() and mx[j + 1] == mx[i]) j++;
		int len = j - i + 1;
		// printf(">u %d: mx %d len %d last %d\n", u, mx[i], j+1, last);
		ans[ 2 * mx[i] ] = max(ans[ 2 * mx[i] ], j + 1);
		ans[ 2 * mx[i]-1 ] = max(ans[ 2 * mx[i]-1 ], j + 1);
		ans[ 2 * mx[i]+1 ] = max(ans[ 2 * mx[i]+1 ], j + 1);
		last = len;
		i = j;
	}
	mx.push_back(0);
	int big = 0;
	for(int v : g[u]) {
		if(h[v] == mx[0]) big = v;
	}
	for(int v : g[u]) if(v != p) {
		if(v == big) h[u] = 1 + mx[1];
		else h[u] = 1 + mx[0];
		int oldv = h[v];
		h[v] = max(h[v], 1 + h[u]);
		auto vec = go(v, u);

		for(int i = 0; i < (int)vec.size(); i++) {
			int j = i;
			while(j + 1 < (int)vec.size() and vec[j + 1] == vec[i])
				j++;
			int cand = j + 1 - (h[u] >= vec[i]);
			cand += count_occ(mx, vec[i]) - (oldv >= vec[i]);
			// printf(">>u %d, v %d: vec %d len %d cand %d\n", u, v, vec[i], j+1+(h[u]<=vec[i]), cand);
			ans[2 * vec[i]] = max(ans[2*vec[i]], cand);
			i = j;
		}

		h[v] = oldv;
		h[u] = 1 + mx[0];
	}
	mx.pop_back();
	return mx;
}

int main() {

	scanf("%d", &n);

	for(int i = 1; i < n; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	prec_h(1, 1);
	go(1, 1);

	for(int i = 1; i <= n; i++) {
		ans[1] = max(ans[1], 1 + int(g[i].size()));
	}

	for(int i = n - 2; i >= 1; i--) {
		ans[i] = max(ans[i], ans[i + 2]);
	}

	for(int i = 1; i <= n; i++) {
		printf("%d%c", ans[i], " \n"[i == n]);
	}

}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 500005;

int n;

vector<int> g[N];
int ans[N];
int h[N];

int count_occ(const vector<int> &vec, int x) {
	return int(vec.rend() -
			lower_bound(vec.rbegin(), vec.rend(), x));
}

int prec_h(int u, int p) {
	h[u] = 1;
	for(int v : g[u]) if(v != p)
		h[u] = max(h[u], 1 + prec_h(v, u));
	return h[u];
}

vector<int> go(int u, int p) {
	auto mx = g[u];
	for(int &x : mx) x = h[x];
	sort(mx.rbegin(), mx.rend());
	int last = 0;
	for(int i = 0; i < (int)mx.size(); i++) {
		int j = i;
		while(j + 1 < (int)mx.size() and mx[j + 1] == mx[i]) j++;
		int len = j - i + 1;
		// printf(">u %d: mx %d len %d last %d\n", u, mx[i], j+1, last);
		ans[ 2 * mx[i] ] = max(ans[ 2 * mx[i] ], j + 1);
		ans[ 2 * mx[i]-1 ] = max(ans[ 2 * mx[i]-1 ], j + 1);
		ans[ 2 * mx[i]+1 ] = max(ans[ 2 * mx[i]+1 ], last + 1);
		ans[ 2 * mx[i]+2 ] = max(ans[ 2 * mx[i]+2 ], last + 1);
		last = j+1;
		i = j;
	}
	mx.push_back(0);
	int big = 0;
	for(int v : g[u]) {
		if(h[v] == mx[0]) big = v;
	}
	for(int v : g[u]) if(v != p) {
		if(v == big) h[u] = 1 + mx[1];
		else h[u] = 1 + mx[0];
		int oldv = h[v];
		h[v] = max(h[v], 1 + h[u]);
		auto vec = go(v, u);

		auto improve = [&mx, &vec, u, oldv](int val) {
			int tmp = count_occ(mx, val) - (oldv >= val);
			tmp += count_occ(vec, val) - (h[u] >= val);
			ans[2*val] = max(ans[2*val], tmp);
		};

		for(int i = 0; i < (int)vec.size(); i++) {
			int j = i;
			while(j + 1 < (int)vec.size() and vec[j + 1] == vec[i])
				j++;
			improve(vec[i] + 1);
			improve(vec[i]);
			improve(vec[i] - 1);
			i = j;
		}

		h[v] = oldv;
		h[u] = 1 + mx[0];
	}
	mx.pop_back();
	return mx;
}

int main() {

	scanf("%d", &n);

	for(int i = 1; i < n; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	prec_h(1, 1);
	for(int i = 1; i <= n; i++) ans[i] = 1;
	go(1, 1);

	for(int i = 1; i <= n; i++) {
		ans[1] = max(ans[1], 1 + int(g[i].size()));
	}

	for(int i = n - 2; i >= 1; i--) {
		ans[i] = max(ans[i], ans[i + 2]);
	}

	for(int i = 1; i <= n; i++) {
		printf("%d%c", ans[i], " \n"[i == n]);
	}

}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 500005;

int n;

vector<int> g[N];
int ans[N];
int h[N];

int count_occ(const vector<int> &vec, int x) {
	return int(vec.rend() -
			lower_bound(vec.rbegin(), vec.rend(), x));
}

int prec_h(int u, int p) {
	h[u] = 1;
	for(int v : g[u]) if(v != p)
		h[u] = max(h[u], 1 + prec_h(v, u));
	return h[u];
}

vector<int> go(int u, int p) {
	auto mx = g[u];
	for(int &x : mx) x = h[x];
	sort(mx.rbegin(), mx.rend());
	int last = 0;
	for(int i = 0; i < (int)mx.size(); i++) {
		int j = i;
		while(j + 1 < (int)mx.size() and mx[j + 1] == mx[i]) j++;
		// int len = j - i + 1;
		// printf(">u %d: mx %d len %d last %d\n", u, mx[i], j+1, last);
		ans[ 2 * mx[i] ] = max(ans[ 2 * mx[i] ], j + 1);
		ans[ 2 * mx[i]-1 ] = max(ans[ 2 * mx[i]-1 ], j + 1);
		ans[ 2 * mx[i]+1 ] = max(ans[ 2 * mx[i]+1 ], last + 1);
		// ans[ 2 * mx[i]+2 ] = max(ans[ 2 * mx[i]+2 ], last);
		last = j+1;
		i = j;
	}
	mx.push_back(0);
	int big = 0;
	for(int v : g[u]) {
		if(h[v] == mx[0]) big = v;
	}
	map<int, int> cnt;
	for(int v : g[u]) if(v != p) {
		if(v == big) h[u] = 1 + mx[1];
		else h[u] = 1 + mx[0];
		int oldv = h[v];
		h[v] = max(h[v], 1 + h[u]);
		auto vec = go(v, u);

		for(int i = 0; i < (int)vec.size(); i++) {
			int j = i;
			while(j + 1 < (int)vec.size() and vec[j + 1] == vec[i])
				j++;
			cnt[ vec[i] ] = max(cnt[ vec[i] ], j + 1);
			i = j;
		}

		h[v] = oldv;
		h[u] = 1 + mx[0];
	}
	mx.pop_back();
	auto improve = [&mx, u](int val, int c2) {
		int tmp = count_occ(mx, val) - 1;
		tmp += c2 - 1;
		ans[2*val] = max(ans[2*val], tmp);
	};
	{
		int cnt_mx = 0;
		for(auto it = cnt.rbegin(); it != cnt.rend(); it++) {
			it->second = cnt_mx = max(cnt_mx, it->second);
		}
	}

	int j = (int)mx.size() - 1;
	for(auto pr : cnt) {
		while(j >= 0 and mx[j] < pr.first) {
			improve(mx[j], pr.second);
			j--;
		}
		improve(pr.first, pr.second);
	}

	return mx;
}

int main() {

	scanf("%d", &n);

	for(int i = 1; i < n; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	prec_h(1, 1);
	for(int i = 1; i <= n; i++) ans[i] = 1;
	go(1, 1);

	for(int i = 1; i <= n; i++) {
		ans[1] = max(ans[1], 1 + int(g[i].size()));
	}

	for(int i = n - 2; i >= 1; i--) {
		ans[i] = max(ans[i], ans[i + 2]);
	}

	for(int i = 1; i <= n; i++) {
		printf("%d%c", ans[i], " \n"[i == n]);
	}

}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 500005;

int n;

vector<int> g[N];
int ans[N];
int h[N];

int count_occ(const vector<int> &vec, int x) {
	return int(vec.rend() -
			lower_bound(vec.rbegin(), vec.rend(), x));
}

int prec_h(int u, int p) {
	h[u] = 1;
	for(int v : g[u]) if(v != p)
		h[u] = max(h[u], 1 + prec_h(v, u));
	return h[u];
}

vector<int> go(int u, int p) {
	auto mx = g[u];
	for(int &x : mx) x = h[x];
	sort(mx.rbegin(), mx.rend());
	int last = 0;
	for(int i = 0; i < (int)mx.size(); i++) {
		int j = i;
		while(j + 1 < (int)mx.size() and mx[j + 1] == mx[i]) j++;
		int len = j - i + 1;
		// printf(">u %d: mx %d len %d last %d\n", u, mx[i], j+1, last);
		ans[ 2 * mx[i] ] = max(ans[ 2 * mx[i] ], j + 1);
		ans[ 2 * mx[i]-1 ] = max(ans[ 2 * mx[i]-1 ], j + 1);
		ans[ 2 * mx[i]+1 ] = max(ans[ 2 * mx[i]+1 ], last + 1);
		ans[ 2 * mx[i]+2 ] = max(ans[ 2 * mx[i]+2 ], last);
		last = j+1;
		i = j;
	}
	mx.push_back(0);
	int big = 0;
	for(int v : g[u]) {
		if(h[v] == mx[0]) big = v;
	}
	for(int v : g[u]) if(v != p) {
		if(v == big) h[u] = 1 + mx[1];
		else h[u] = 1 + mx[0];
		int oldv = h[v];
		h[v] = max(h[v], 1 + h[u]);
		auto vec = go(v, u);

		auto improve = [&mx, &vec, u, oldv](int val) {
			int tmp = count_occ(mx, val) - (oldv >= val);
			tmp += count_occ(vec, val) - (h[u] >= val);
			ans[2*val] = max(ans[2*val], tmp);
		};

		for(int i = 0; i < (int)vec.size(); i++) {
			int j = i;
			while(j + 1 < (int)vec.size() and vec[j + 1] == vec[i])
				j++;
			improve(vec[i] + 1);
			improve(vec[i]);
			improve(vec[i] - 1);
			i = j;
		}

		h[v] = oldv;
		h[u] = 1 + mx[0];
	}
	mx.pop_back();
	return mx;
}

int main() {

	scanf("%d", &n);

	for(int i = 1; i < n; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	prec_h(1, 1);
	for(int i = 1; i <= n; i++) ans[i] = 1;
	go(1, 1);

	for(int i = 1; i <= n; i++) {
		ans[1] = max(ans[1], 1 + int(g[i].size()));
	}

	for(int i = n - 2; i >= 1; i--) {
		ans[i] = max(ans[i], ans[i + 2]);
	}

	for(int i = 1; i <= n; i++) {
		printf("%d%c", ans[i], " \n"[i == n]);
	}

}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 500005;

int n;

vector<int> g[N];
int ans[N];
int h[N];

int count_occ(const vector<int> &vec, int x) {
	return int(vec.rend() -
			lower_bound(vec.rbegin(), vec.rend(), x));
}

int prec_h(int u, int p) {
	h[u] = 1;
	for(int v : g[u]) if(v != p)
		h[u] = max(h[u], 1 + prec_h(v, u));
	return h[u];
}

vector<int> go(int u, int p) {
	auto mx = g[u];
	for(int &x : mx) x = h[x];
	sort(mx.rbegin(), mx.rend());
	int last = 0;
	for(int i = 0; i < (int)mx.size(); i++) {
		int j = i;
		while(j + 1 < (int)mx.size() and mx[j + 1] == mx[i]) j++;
		int len = j - i + 1;
		// printf(">u %d: mx %d len %d last %d\n", u, mx[i], j+1, last);
		ans[ 2 * mx[i] ] = max(ans[ 2 * mx[i] ], j + 1);
		ans[ 2 * mx[i]-1 ] = max(ans[ 2 * mx[i]-1 ], j + 1);
		ans[ 2 * mx[i]+1 ] = max(ans[ 2 * mx[i]+1 ], last + 1);
		ans[ 2 * mx[i]+2 ] = max(ans[ 2 * mx[i]+2 ], last);
		last = j+1;
		i = j;
	}
	mx.push_back(0);
	int big = 0;
	for(int v : g[u]) {
		if(h[v] == mx[0]) big = v;
	}
	for(int v : g[u]) if(v != p) {
		if(v == big) h[u] = 1 + mx[1];
		else h[u] = 1 + mx[0];
		int oldv = h[v];
		h[v] = max(h[v], 1 + h[u]);
		auto vec = go(v, u);

		for(int i = 0; i < (int)vec.size(); i++) {
			ans[2*vec[i]+2] = max(ans[2*vec[i]+2], i-(h[u]>vec[i])+count_occ(mx, vec[i]+1) - (oldv > vec[i]));
			int j = i;
			while(j + 1 < (int)vec.size() and vec[j + 1] == vec[i])
				j++;
			int cand = j + 1 - (h[u] >= vec[i]);
			cand += count_occ(mx, vec[i]) - (oldv >= vec[i]);
			// printf(">>u %d, v %d: vec %d len %d cand %d\n", u, v, vec[i], j+1+(h[u]<=vec[i]), cand);
			ans[2 * vec[i]] = max(ans[2*vec[i]], cand);
			i = j;
		}

		h[v] = oldv;
		h[u] = 1 + mx[0];
	}
	mx.pop_back();
	return mx;
}

int main() {

	scanf("%d", &n);

	for(int i = 1; i < n; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	prec_h(1, 1);
	for(int i = 1; i <= n; i++) ans[i] = 1;
	go(1, 1);

	for(int i = 1; i <= n; i++) {
		ans[1] = max(ans[1], 1 + int(g[i].size()));
	}

	for(int i = n - 2; i >= 1; i--) {
		ans[i] = max(ans[i], ans[i + 2]);
	}

	for(int i = 1; i <= n; i++) {
		printf("%d%c", ans[i], " \n"[i == n]);
	}

}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 500005;

int n;

vector<int> g[N];
int ans[N];
int h[N];

int count_occ(const vector<int> &vec, int x) {
	return int(upper_bound(vec.rbegin(), vec.rend(), x) -
			lower_bound(vec.rbegin(), vec.rend(), x));
}

int prec_h(int u, int p) {
	h[u] = 1;
	for(int v : g[u]) if(v != p)
		h[u] = max(h[u], 1 + prec_h(v, u));
	return h[u];
}

vector<int> go(int u, int p) {
	auto mx = g[u];
	for(int &x : mx) x = h[x];
	sort(mx.rbegin(), mx.rend());
	int last = 0;
	for(int i = 0; i < (int)mx.size(); i++) {
		int j = i;
		while(j + 1 < (int)mx.size() and mx[j + 1] == mx[i]) j++;
		int len = j - i + 1;
		// printf(">u %d: mx %d len %d last %d\n", u, mx[i], len, last);
		ans[ 2 * mx[i] ] = max(ans[ 2 * mx[i] ], len + !!last);
		ans[ 2 * mx[i]+1 ] = max(ans[ 2 * mx[i]+1 ], !!len + last);
		last = len;
		i = j;
	}
	mx.push_back(0);
	int big = 0;
	for(int v : g[u]) {
		if(h[v] == mx[0]) big = v;
	}
	for(int v : g[u]) if(v != p) {
		if(v == big) h[u] = 1 + mx[1];
		else h[u] = 1 + mx[0];
		int oldv = h[v];
		h[v] = max(h[v], 1 + h[u]);
		auto vec = go(v, u);

		for(int i = 0; i < (int)vec.size(); i++) {
			int j = i;
			while(j + 1 < (int)vec.size() and vec[j + 1] == vec[i])
				j++;
			int cand = j - i + 1 - (h[u] == vec[i]);
			cand += count_occ(mx, vec[i]) - (oldv == vec[i]);
			// printf(">>u %d, v %d: vec %d len %d cand %d\n", u, v, vec[i], j-i+1, cand);
			ans[2 * vec[i]] = max(ans[2*vec[i]], cand);
			ans[2 * vec[i]-1] = max(ans[2*vec[i]-1], cand);
			i = j;
		}

		h[v] = oldv;
		h[u] = 1 + mx[0];
	}
	mx.pop_back();
	return mx;
}

int main() {

	scanf("%d", &n);

	for(int i = 1; i < n; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	prec_h(1, 1);
	go(1, 1);

	for(int i = 1; i <= n; i++) {
		ans[1] = max(ans[1], 1 + int(g[i].size()));
	}

	for(int i = 1; i <= n; i++) {
		printf("%d%c", ans[i], " \n"[i == n]);
	}

}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 500005;

int n;

vector<int> g[N];
int ans[N];
int h[N];

int count_occ(const vector<int> &vec, int x) {
	return int(upper_bound(vec.rbegin(), vec.rend(), x) -
			lower_bound(vec.rbegin(), vec.rend(), x));
}

int prec_h(int u, int p) {
	h[u] = 1;
	for(int v : g[u]) if(v != p)
		h[u] = max(h[u], 1 + prec_h(v, u));
	return h[u];
}

vector<int> go(int u, int p) {
	auto mx = g[u];
	for(int &x : mx) x = h[x];
	sort(mx.rbegin(), mx.rend());
	int last = 0;
	for(int i = 0; i < (int)mx.size(); i++) {
		int j = i;
		while(j + 1 < (int)mx.size() and mx[j + 1] == mx[i]) j++;
		int len = j - i + 1;
		// printf(">u %d: mx %d len %d last %d\n", u, mx[i], len, last);
		ans[ 2 * mx[i] ] = max(ans[ 2 * mx[i] ], len + !!last);
		ans[ 2 * mx[i]+1 ] = max(ans[ 2 * mx[i]+1 ], !!len + last);
		last = len;
		i = j;
	}
	mx.push_back(0);
	int big = 0;
	for(int v : g[u]) {
		if(h[v] == mx[0]) big = v;
	}
	for(int v : g[u]) if(v != p) {
		if(v == big) h[u] = 1 + mx[1];
		else h[u] = 1 + mx[0];
		int oldv = h[v];
		h[v] = max(h[v], 1 + h[u]);
		auto vec = go(v, u);

		for(int i = 0; i < (int)vec.size(); i++) {
			int j = i;
			while(j + 1 < (int)vec.size() and vec[j + 1] == vec[i])
				j++;
			int cand = j - i + 1 - (h[u] == vec[i]);
			cand += count_occ(mx, vec[i]) - (oldv == vec[i]);
			// printf(">>u %d, v %d: vec %d len %d cand %d\n", u, v, vec[i], j-i+1, cand);
			ans[2 * vec[i]] = max(ans[2*vec[i]], cand);
			ans[2 * vec[i]-1] = max(ans[2*vec[i]-1], cand);
			i = j;
		}

		h[v] = oldv;
		h[u] = 1 + mx[0];
	}
	mx.pop_back();
	return mx;
}

int main() {

	scanf("%d", &n);

	for(int i = 1; i < n; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	prec_h(1, 1);
	go(1, 1);

	for(int i = 1; i <= n; i++) {
		ans[1] = max(ans[1], 1 + int(g[i].size()));
	}

	for(int i = n - 2; i >= 1; i--) {
		ans[i] = max(ans[i], ans[i + 2]);
	}

	for(int i = 1; i <= n; i++) {
		printf("%d%c", ans[i], " \n"[i == n]);
	}

}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 500005;

int n;

vector<int> g[N];
int ans[N];
int h[N];

int count_occ(const vector<int> &vec, int x) {
	return int(vec.rend() -
			lower_bound(vec.rbegin(), vec.rend(), x));
}

int prec_h(int u, int p) {
	h[u] = 1;
	for(int v : g[u]) if(v != p)
		h[u] = max(h[u], 1 + prec_h(v, u));
	return h[u];
}

vector<int> go(int u, int p) {
	auto mx = g[u];
	for(int &x : mx) x = h[x];
	sort(mx.rbegin(), mx.rend());
	int last = 0;
	for(int i = 0; i < (int)mx.size(); i++) {
		int j = i;
		while(j + 1 < (int)mx.size() and mx[j + 1] == mx[i]) j++;
		int len = j - i + 1;
		// printf(">u %d: mx %d len %d last %d\n", u, mx[i], j+1, last);
		ans[ 2 * mx[i] ] = max(ans[ 2 * mx[i] ], j + 1);
		ans[ 2 * mx[i]-1 ] = max(ans[ 2 * mx[i]-1 ], j + 1);
		ans[ 2 * mx[i]+1 ] = max(ans[ 2 * mx[i]+1 ], last + 1);
		ans[ 2 * mx[i]+2 ] = max(ans[ 2 * mx[i]+2 ], last + 1);
		last = j+1;
		i = j;
	}
	mx.push_back(0);
	int big = 0;
	for(int v : g[u]) {
		if(h[v] == mx[0]) big = v;
	}
	for(int v : g[u]) if(v != p) {
		if(v == big) h[u] = 1 + mx[1];
		else h[u] = 1 + mx[0];
		int oldv = h[v];
		h[v] = max(h[v], 1 + h[u]);
		auto vec = go(v, u);

		for(int i = 0; i < (int)vec.size(); i++) {
			ans[2*vec[i]+2] = max(ans[2*vec[i]+2], i-(h[u]>vec[i])+count_occ(mx, vec[i]+1) - (oldv > vec[i]));
			int j = i;
			while(j + 1 < (int)vec.size() and vec[j + 1] == vec[i])
				j++;
			int cand = j + 1 - (h[u] >= vec[i]);
			cand += count_occ(mx, vec[i]) - (oldv >= vec[i]);
			// printf(">>u %d, v %d: vec %d len %d cand %d\n", u, v, vec[i], j+1+(h[u]<=vec[i]), cand);
			ans[2 * vec[i]] = max(ans[2*vec[i]], cand);
			i = j;
		}

		h[v] = oldv;
		h[u] = 1 + mx[0];
	}
	mx.pop_back();
	return mx;
}

int main() {

	scanf("%d", &n);

	for(int i = 1; i < n; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	prec_h(1, 1);
	for(int i = 1; i <= n; i++) ans[i] = 1;
	go(1, 1);

	for(int i = 1; i <= n; i++) {
		ans[1] = max(ans[1], 1 + int(g[i].size()));
	}

	for(int i = n - 2; i >= 1; i--) {
		ans[i] = max(ans[i], ans[i + 2]);
	}

	for(int i = 1; i <= n; i++) {
		printf("%d%c", ans[i], " \n"[i == n]);
	}

}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 500005;

int n;

vector<int> g[N];
int ans[N];
int h[N];

int count_occ(const vector<int> &vec, int x) {
	return int(vec.rend() -
			lower_bound(vec.rbegin(), vec.rend(), x));
}

int prec_h(int u, int p) {
	h[u] = 1;
	for(int v : g[u]) if(v != p)
		h[u] = max(h[u], 1 + prec_h(v, u));
	return h[u];
}

vector<int> go(int u, int p) {
	auto mx = g[u];
	for(int &x : mx) x = h[x];
	sort(mx.rbegin(), mx.rend());
	int last = 0;
	for(int i = 0; i < (int)mx.size(); i++) {
		int j = i;
		while(j + 1 < (int)mx.size() and mx[j + 1] == mx[i]) j++;
		int len = j - i + 1;
		// printf(">u %d: mx %d len %d last %d\n", u, mx[i], j+1, last);
		ans[ 2 * mx[i] ] = max(ans[ 2 * mx[i] ], j + 1);
		ans[ 2 * mx[i]-1 ] = max(ans[ 2 * mx[i]-1 ], j + 1);
		ans[ 2 * mx[i]+1 ] = max(ans[ 2 * mx[i]+1 ], last + 1);
		last = j+1;
		i = j;
	}
	mx.push_back(0);
	int big = 0;
	for(int v : g[u]) {
		if(h[v] == mx[0]) big = v;
	}
	for(int v : g[u]) if(v != p) {
		if(v == big) h[u] = 1 + mx[1];
		else h[u] = 1 + mx[0];
		int oldv = h[v];
		h[v] = max(h[v], 1 + h[u]);
		auto vec = go(v, u);

		for(int i = 0; i < (int)vec.size(); i++) {
			int j = i;
			while(j + 1 < (int)vec.size() and vec[j + 1] == vec[i])
				j++;
			int cand = j + 1 - (h[u] >= vec[i]);
			cand += count_occ(mx, vec[i]) - (oldv >= vec[i]);
			// printf(">>u %d, v %d: vec %d len %d cand %d\n", u, v, vec[i], j+1+(h[u]<=vec[i]), cand);
			ans[2 * vec[i]] = max(ans[2*vec[i]], cand);
			i = j;
		}

		h[v] = oldv;
		h[u] = 1 + mx[0];
	}
	mx.pop_back();
	return mx;
}

int main() {

	scanf("%d", &n);

	for(int i = 1; i < n; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	prec_h(1, 1);
	go(1, 1);

	for(int i = 1; i <= n; i++) {
		ans[1] = max(ans[1], 1 + int(g[i].size()));
	}

	for(int i = n - 2; i >= 1; i--) {
		ans[i] = max(ans[i], ans[i + 2]);
	}

	for(int i = 1; i <= n; i++) {
		printf("%d%c", ans[i], " \n"[i == n]);
	}

}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
vector<int> g[500001];
vector<pii> ret[500001];
vector<int> ret2[500001];
vector<pii> maxai[500001];

int ans[500002];

int dfs(int v, int p){
    vector<int> toLeave;

    for(int i:g[v]){
        if(i==p){
            toLeave.push_back(i);
            continue;
        }
        ret[v].push_back({dfs(i, v),i});
        ret2[v].push_back(ret[v].back().first);

        maxai[v].push_back(ret[v].back());
        sort(maxai[v].rbegin(), maxai[v].rend());
        if(maxai[v].size()>2){
            maxai[v].pop_back();
        }
    }
    int cnt = 0;
    if(maxai[v].size()>0&&!(maxai[v].size()==1&&maxai[v][0].second==p)){
        cnt = maxai[v][0].first;
        if(maxai[v][0].second==p){
            cnt=maxai[v][1].first;
        }
    }
    g[v]=toLeave;
    return cnt+1;
}

int ind[500001];
unordered_map<int, int, custom_hash> tried[500001];
int newret[500000];
int main()
{
    int n; scanf("%d", &n);

    vector<pii> edges;

    for(int i=1; i<=n-1; i++){
        int u, v; scanf("%d %d", &u, &v);
        g[u].push_back(v);
        g[v].push_back(u);
        edges.push_back({u,v});
    }
    for(int i=1; i<=n; i++){
        ans[i]=1;
        ans[1] = max(ans[1], (int)g[i].size()+1);
    }

    map<vector<int>, int> mp;

    for(int i=1; i<=n; i++){
        dfs(i,i);
        sort(ret2[i].rbegin(), ret2[i].rend());
        for(int j=1; j<ret2[i].size(); j++){
            int pirmas = ret2[i][j];
            int antras = ret2[i][j-1];
            if(pirmas==antras){
                ans[pirmas*2]=max(ans[pirmas*2], j+1);
            }
            else{
                ans[pirmas*2+1]=max(ans[pirmas*2+1], j+1);
            }
        }
        if(!mp.count(ret2[i])){
            mp[ret2[i]]=mp.size();
            ind[i]=mp.size();
        }
        else{
            ind[i]=mp[ret2[i]];
        }

    }
    for(int i=n-1; i>=1; i--){
        ans[i]=max(ans[i], ans[i+1]);
    }
    for(pii i:edges){
        int pirmas = ind[i.first];
        int antras = ind[i.second];
        if(tried[pirmas].count(antras)){
            continue;
        }
        tried[pirmas][antras]=1;
        tried[antras][pirmas]=1;
        int cnt = 0;
        //vector<int> newret;

        for(pii j:ret[i.first]){
            if(j.second!=i.second){
                newret[cnt]=j.first;
                cnt++;
            }
        }
        for(pii j:ret[i.second]){
            if(j.second!=i.first){
                newret[cnt]=j.first;
                cnt++;
            }
        }
        sort(newret, newret+cnt, greater<int>());
        for(int j=1; j<cnt; j++){
            ans[newret[j]*2] = max(ans[newret[j]*2], j+1);
        }
    }

    for(int i=n-1; i>=1; i--){
        ans[i]=max(ans[i], ans[i+2]);
    }
    for(int i=1; i<=n; i++){
        printf("%d ", ans[i]);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
namespace std{
    template<>struct hash<vector<int> >{
        size_t operator()(vector<int> const& v) const{
          unsigned long long h=0;
          for(auto &x:v)
            h<<=32,h^=hash<int>()(x),h=hash<long long>()(h);
          return h;
        }
    };
}
vector<int> g[500001];
vector<pii> ret[500001];
vector<int> ret2[500001];
vector<pii> maxai[500001];

int ans[500002];

int dfs(int v, int p){
    vector<int> toLeave;

    for(int i:g[v]){
        if(i==p){
            toLeave.push_back(i);
            continue;
        }
        ret[v].push_back({dfs(i, v),i});
        ret2[v].push_back(ret[v].back().first);

        maxai[v].push_back(ret[v].back());
        sort(maxai[v].rbegin(), maxai[v].rend());
        if(maxai[v].size()>2){
            maxai[v].pop_back();
        }
    }
    int cnt = 0;
    if(maxai[v].size()>0&&!(maxai[v].size()==1&&maxai[v][0].second==p)){
        cnt = maxai[v][0].first;
        if(maxai[v][0].second==p){
            cnt=maxai[v][1].first;
        }
    }
    g[v]=toLeave;
    return cnt+1;
}

int ind[500001];
unordered_map<int, int, custom_hash> tried[500001];

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n; cin>>n;

    vector<pii> edges;

    for(int i=1; i<=n-1; i++){
        int u, v; cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
        edges.push_back({u,v});
    }
    for(int i=1; i<=n; i++){
        ans[i]=1;
        ans[1] = max(ans[1], (int)g[i].size()+1);
    }

    unordered_map<vector<int>, int,hash<vector<int> >> mp;

    for(int i=1; i<=n; i++){
        dfs(i,i);
        sort(ret2[i].rbegin(), ret2[i].rend());
        for(int j=1; j<ret2[i].size(); j++){
            int pirmas = ret2[i][j];
            int antras = ret2[i][j-1];
            if(pirmas==antras){
                ans[pirmas*2]=max(ans[pirmas*2], j+1);
            }
            else{
                ans[pirmas*2+1]=max(ans[pirmas*2+1], j+1);
            }
        }
        if(!mp.count(ret2[i])){
            mp[ret2[i]]=mp.size();
        }

    }
    for(int i=1; i<=n; i++){
        ind[i] = mp[ret2[i]];
    }
    for(int i=n-1; i>=1; i--){
        ans[i]=max(ans[i], ans[i+1]);
    }
    for(pii i:edges){
        int pirmas = ind[i.first];
        int antras = ind[i.second];
        if(tried[pirmas].count(antras)){
            continue;
        }
        tried[pirmas][antras]=1;
        tried[antras][pirmas]=1;
        vector<int> newret;
        for(pii j:ret[i.first]){
            if(j.second!=i.second){
                newret.push_back(j.first);
            }
        }
        for(pii j:ret[i.second]){
            if(j.second!=i.first){
                newret.push_back(j.first);
            }
        }
        sort(newret.rbegin(), newret.rend());
        for(int j=1; j<newret.size(); j++){
            ans[newret[j]*2] = max(ans[newret[j]*2], j+1);
        }
    }

    for(int i=n-1; i>=1; i--){
        ans[i]=max(ans[i], ans[i+2]);
    }
    for(int i=1; i<=n; i++){
        cout<<ans[i]<<' ';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
vector<int> g[500001];
vector<pii> ret[500001];
vector<int> ret2[500001];
vector<pii> maxai[500001];

int ans[500002];

int dfs(int v, int p){
    vector<int> toLeave;

    for(int i:g[v]){
        if(i==p){
            toLeave.push_back(i);
            continue;
        }
        ret[v].push_back({dfs(i, v),i});
        ret2[v].push_back(ret[v].back().first);

        maxai[v].push_back(ret[v].back());
        sort(maxai[v].rbegin(), maxai[v].rend());
        if(maxai[v].size()>2){
            maxai[v].pop_back();
        }
    }
    int cnt = 0;
    if(maxai[v].size()>0&&!(maxai[v].size()==1&&maxai[v][0].second==p)){
        cnt = maxai[v][0].first;
        if(maxai[v][0].second==p){
            cnt=maxai[v][1].first;
        }
    }
    g[v]=toLeave;
    return cnt+1;
}

int ind[500001];
unordered_map<int, int, custom_hash> tried[500001];

int main()
{
    int n; scanf("%d", &n);

    vector<pii> edges;

    for(int i=1; i<=n-1; i++){
        int u, v; scanf("%d %d", &u, &v);
        g[u].push_back(v);
        g[v].push_back(u);
        edges.push_back({u,v});
    }
    for(int i=1; i<=n; i++){
        ans[i]=1;
        ans[1] = max(ans[1], (int)g[i].size()+1);
    }

    map<vector<int>, int> mp;

    for(int i=1; i<=n; i++){
        dfs(i,i);
        sort(ret2[i].rbegin(), ret2[i].rend());
        for(int j=1; j<ret2[i].size(); j++){
            int pirmas = ret2[i][j];
            int antras = ret2[i][j-1];
            if(pirmas==antras){
                ans[pirmas*2]=max(ans[pirmas*2], j+1);
            }
            else{
                ans[pirmas*2+1]=max(ans[pirmas*2+1], j+1);
            }
        }
        if(!mp.count(ret2[i])){
            mp[ret2[i]]=mp.size();
        }

    }
    for(int i=1; i<=n; i++){
        ind[i] = mp[ret2[i]];
    }
    for(int i=n-1; i>=1; i--){
        ans[i]=max(ans[i], ans[i+1]);
    }
    for(pii i:edges){
        int pirmas = ind[i.first];
        int antras = ind[i.second];
        if(tried[pirmas].count(antras)){
            continue;
        }
        tried[pirmas][antras]=1;
        tried[antras][pirmas]=1;
        vector<int> newret;
        for(pii j:ret[i.first]){
            if(j.second!=i.second){
                newret.push_back(j.first);
            }
        }
        for(pii j:ret[i.second]){
            if(j.second!=i.first){
                newret.push_back(j.first);
            }
        }
        sort(newret.rbegin(), newret.rend());
        for(int j=1; j<newret.size(); j++){
            ans[newret[j]*2] = max(ans[newret[j]*2], j+1);
        }
    }

    for(int i=n-1; i>=1; i--){
        ans[i]=max(ans[i], ans[i+2]);
    }
    for(int i=1; i<=n; i++){
        printf("%d ", ans[i]);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

vector<int> g[500001];
vector<pii> ret[500001];
vector<int> ret2[500001];
vector<pii> maxai[500001];

int ans[500002];

int dfs(int v, int p){
    vector<int> toLeave;

    for(int i:g[v]){
        if(i==p){
            toLeave.push_back(i);
            continue;
        }
        ret[v].push_back({dfs(i, v),i});
        ret2[v].push_back(ret[v].back().first);

        maxai[v].push_back(ret[v].back());
        sort(maxai[v].rbegin(), maxai[v].rend());
        if(maxai[v].size()>2){
            maxai[v].pop_back();
        }
    }
    int cnt = 0;
    if(maxai[v].size()>0&&!(maxai[v].size()==1&&maxai[v][0].second==p)){
        cnt = maxai[v][0].first;
        if(maxai[v][0].second==p){
            cnt=maxai[v][1].first;
        }
    }
    g[v]=toLeave;
    return cnt+1;
}

int ind[500001];

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n; cin>>n;

    vector<pii> edges;

    for(int i=1; i<=n-1; i++){
        int u, v; cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
        edges.push_back({u,v});
    }
    for(int i=1; i<=n; i++){
        ans[i]=1;
        ans[1] = max(ans[1], (int)g[i].size()+1);
    }

    map<vector<int>, int> mp;

    for(int i=1; i<=n; i++){
        dfs(i,i);
        sort(ret2[i].rbegin(), ret2[i].rend());
        for(int j=1; j<ret2[i].size(); j++){
            int pirmas = ret2[i][j];
            int antras = ret2[i][j-1];
            if(pirmas==antras){
                ans[pirmas*2]=max(ans[pirmas*2], j+1);
            }
            else{
                ans[pirmas*2+1]=max(ans[pirmas*2+1], j+1);
            }
        }
        if(!mp.count(ret2[i])){
            mp[ret2[i]]=mp.size();
        }

    }
    for(int i=1; i<=n; i++){
        ind[i] = mp[ret2[i]];
    }
    for(int i=n-1; i>=1; i--){
        ans[i]=max(ans[i], ans[i+1]);
    }
    set<pii> tried;
    for(pii i:edges){
        int pirmas = ind[i.first];
        int antras = ind[i.second];
        if(tried.count({pirmas, antras})){
            continue;
        }
        tried.insert({pirmas,antras});
        tried.insert({antras,pirmas});
        vector<int> newret;
        for(pii j:ret[i.first]){
            if(j.second!=i.second){
                newret.push_back(j.first);
            }
        }
        for(pii j:ret[i.second]){
            if(j.second!=i.first){
                newret.push_back(j.first);
            }
        }
        sort(newret.rbegin(), newret.rend());
        for(int j=1; j<newret.size(); j++){
            ans[newret[j]*2] = max(ans[newret[j]*2], j+1);
        }
    }

    for(int i=n-1; i>=1; i--){
        ans[i]=max(ans[i], ans[i+2]);
    }
    for(int i=1; i<=n; i++){
        cout<<ans[i]<<' ';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

vector<int> g[500001];
vector<pii> ret[500001];
vector<pii> maxai[500001];

int ans[500002];

int dfs(int v, int p){
    vector<int> toLeave;

    for(int i:g[v]){
        if(i==p){
            toLeave.push_back(i);
            continue;
        }
        ret[v].push_back({dfs(i, v),i});
        maxai[v].push_back(ret[v].back());
        sort(maxai[v].rbegin(), maxai[v].rend());
        if(maxai[v].size()>2){
            maxai[v].pop_back();
        }
    }
    int cnt = 0;
    if(maxai[v].size()>0&&!(maxai[v].size()==1&&maxai[v][0].second==p)){
        cnt = maxai[v][0].first;
        if(maxai[v][0].second==p){
            cnt=maxai[v][1].first;
        }
    }
    g[v]=toLeave;
    return cnt+1;
}

int main()
{
    int n; cin>>n;

    vector<pii> edges;

    for(int i=1; i<=n-1; i++){
        int u, v; cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
        edges.push_back({u,v});
    }
    for(int i=1; i<=n; i++){
        ans[i]=1;
        ans[1] = max(ans[1], (int)g[i].size()+1);
    }
    for(int i=1; i<=n; i++){
        dfs(i,i);
        sort(ret[i].rbegin(), ret[i].rend());
        for(int j=1; j<ret[i].size(); j++){
            int pirmas = ret[i][j].first;
            int antras = ret[i][j-1].first;
            //cout<<i<<' '<<pirmas<<' '<<antras<<' '<<j+1<<endl;
            if(pirmas==antras){
                ans[pirmas*2]=max(ans[pirmas*2], j+1);
            }
            else{
                ans[pirmas*2+1]=max(ans[pirmas*2+1], j+1);
            }
        }
    }
    for(pii i:edges){
        vector<int> newret;
        multiset<int> s;
        for(pii j:ret[i.first]){
            if(j.second!=i.second){
                newret.push_back(j.first);
            }
        }
        for(pii j:ret[i.second]){
            if(j.second!=i.first){
                newret.push_back(j.first);
            }
        }
        sort(newret.rbegin(), newret.rend());
        for(int j=1; j<newret.size(); j++){
            ans[newret[j]*2] = max(ans[newret[j]*2], j+1);
        }
    }

    for(int i=n-1; i>=1; i--){
        ans[i]=max(ans[i], ans[i+2]);
    }
    for(int i=1; i<=n; i++){
        cout<<ans[i]<<' ';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

vector<int> g[500001];
vector<pii> ret[500001];
vector<int> ret2[500001];
vector<pii> maxai[500001];

int ans[500002];

int dfs(int v, int p){
    vector<int> toLeave;

    for(int i:g[v]){
        if(i==p){
            toLeave.push_back(i);
            continue;
        }
        ret[v].push_back({dfs(i, v),i});
        ret2[v].push_back(ret[v].back().first);

        maxai[v].push_back(ret[v].back());
        sort(maxai[v].rbegin(), maxai[v].rend());
        if(maxai[v].size()>2){
            maxai[v].pop_back();
        }
    }
    int cnt = 0;
    if(maxai[v].size()>0&&!(maxai[v].size()==1&&maxai[v][0].second==p)){
        cnt = maxai[v][0].first;
        if(maxai[v][0].second==p){
            cnt=maxai[v][1].first;
        }
    }
    g[v]=toLeave;
    return cnt+1;
}

int ind[500001];

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n; cin>>n;

    vector<pii> edges;

    for(int i=1; i<=n-1; i++){
        int u, v; cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
        edges.push_back({u,v});
    }
    for(int i=1; i<=n; i++){
        ans[i]=1;
        ans[1] = max(ans[1], (int)g[i].size()+1);
    }

    map<vector<int>, int> mp;

    for(int i=1; i<=n; i++){
        dfs(i,i);
        sort(ret2[i].rbegin(), ret2[i].rend());
        for(int j=1; j<ret2[i].size(); j++){
            int pirmas = ret2[i][j];
            int antras = ret2[i][j-1];
            if(pirmas==antras){
                ans[pirmas*2]=max(ans[pirmas*2], j+1);
            }
            else{
                ans[pirmas*2+1]=max(ans[pirmas*2+1], j+1);
            }
        }
        if(!mp.count(ret2[i])){
            ind[i]=mp.size();
            mp[ret2[i]]=mp.size();
        }
        else{
            ind[i]=mp[ret2[i]];
        }

    }
    for(int i=n-1; i>=1; i--){
        ans[i]=max(ans[i], ans[i+1]);
    }
    set<pii> tried;
    for(pii i:edges){
        int pirmas = ind[i.first];
        int antras = ind[i.second];
        if(tried.count({pirmas, antras})){
            continue;
        }
        tried.insert({pirmas,antras});
        tried.insert({antras,pirmas});
        vector<int> newret;
        for(pii j:ret[i.first]){
            if(j.second!=i.second){
                newret.push_back(j.first);
            }
        }
        for(pii j:ret[i.second]){
            if(j.second!=i.first){
                newret.push_back(j.first);
            }
        }
        sort(newret.rbegin(), newret.rend());
        for(int j=1; j<newret.size(); j++){
            ans[newret[j]*2] = max(ans[newret[j]*2], j+1);
        }
    }

    for(int i=n-1; i>=1; i--){
        ans[i]=max(ans[i], ans[i+2]);
    }
    for(int i=1; i<=n; i++){
        cout<<ans[i]<<' ';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

vector<int> g[500001];
vector<pii> ret[500001];
vector<int> ret2[500001];
vector<pii> maxai[500001];

int ans[500002];

int dfs(int v, int p){
    vector<int> toLeave;

    for(int i:g[v]){
        if(i==p){
            toLeave.push_back(i);
            continue;
        }
        ret[v].push_back({dfs(i, v),i});
        ret2[v].push_back(ret[v].back().first);

        maxai[v].push_back(ret[v].back());
        sort(maxai[v].rbegin(), maxai[v].rend());
        if(maxai[v].size()>2){
            maxai[v].pop_back();
        }
    }
    int cnt = 0;
    if(maxai[v].size()>0&&!(maxai[v].size()==1&&maxai[v][0].second==p)){
        cnt = maxai[v][0].first;
        if(maxai[v][0].second==p){
            cnt=maxai[v][1].first;
        }
    }
    g[v]=toLeave;
    return cnt+1;
}

int ind[500001];
unordered_map<int, int, custom_hash> tried[500001];

inline int read()
{
	char ch = getchar();
	int x = 0;
	while(ch >= '0' && ch <= '9')
	{
		x = x * 10 + (ch - '0');
		ch = getchar();
	}
	return x;
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n=read();

    vector<pii> edges;

    for(int i=1; i<=n-1; i++){
        int u=read(), v=read();
        g[u].push_back(v);
        g[v].push_back(u);
        edges.push_back({u,v});
    }
    for(int i=1; i<=n; i++){
        ans[i]=1;
        ans[1] = max(ans[1], (int)g[i].size()+1);
    }

    map<vector<int>, int> mp;

    for(int i=1; i<=n; i++){
        dfs(i,i);
        sort(ret2[i].rbegin(), ret2[i].rend());
        for(int j=1; j<ret2[i].size(); j++){
            int pirmas = ret2[i][j];
            int antras = ret2[i][j-1];
            if(pirmas==antras){
                ans[pirmas*2]=max(ans[pirmas*2], j+1);
            }
            else{
                ans[pirmas*2+1]=max(ans[pirmas*2+1], j+1);
            }
        }
        if(!mp.count(ret2[i])){
            mp[ret2[i]]=mp.size();
        }

    }
    for(int i=1; i<=n; i++){
        ind[i] = mp[ret2[i]];
    }
    for(int i=n-1; i>=1; i--){
        ans[i]=max(ans[i], ans[i+1]);
    }
    for(pii i:edges){
        int pirmas = ind[i.first];
        int antras = ind[i.second];
        if(tried[pirmas].count(antras)){
            continue;
        }
        tried[pirmas][antras]=1;
        tried[antras][pirmas]=1;
        vector<int> newret;
        for(pii j:ret[i.first]){
            if(j.second!=i.second){
                newret.push_back(j.first);
            }
        }
        for(pii j:ret[i.second]){
            if(j.second!=i.first){
                newret.push_back(j.first);
            }
        }
        sort(newret.rbegin(), newret.rend());
        for(int j=1; j<newret.size(); j++){
            ans[newret[j]*2] = max(ans[newret[j]*2], j+1);
        }
    }

    for(int i=n-1; i>=1; i--){
        ans[i]=max(ans[i], ans[i+2]);
    }
    for(int i=1; i<=n; i++){
        cout<<ans[i]<<' ';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

vector<int> g[500001];
vector<pii> ret[500001];
vector<pii> maxai[500001];

int ans[500001];

int dfs(int v, int p){
    vector<int> toLeave;

    for(int i:g[v]){
        if(i==p){
            toLeave.push_back(i);
            continue;
        }
        ret[v].push_back({dfs(i, v),i});
        maxai[v].push_back(ret[v].back());
        sort(maxai[v].rbegin(), maxai[v].rend());
        if(maxai[v].size()>2){
            maxai[v].pop_back();
        }
    }
    int cnt = 0;
    if(maxai[v].size()>0&&!(maxai[v].size()==1&&maxai[v][0].second==p)){
        cnt = maxai[v][0].first;
        if(maxai[v][0].second==p){
            cnt=maxai[v][1].first;
        }
    }
    g[v]=toLeave;
    return cnt+1;
}

int main()
{
    int n; cin>>n;

    vector<pii> edges;

    for(int i=1; i<=n-1; i++){
        int u, v; cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
        edges.push_back({u,v});
    }
    for(int i=1; i<=n; i++){
        ans[i]=1;
        ans[1] = max(ans[1], (int)g[i].size()+1);
    }
    for(int i=1; i<=n; i++){
        dfs(i,i);
        sort(ret[i].rbegin(), ret[i].rend());
        for(int j=1; j<ret[i].size(); j++){
            int pirmas = ret[i][j].first;
            int antras = ret[i][j-1].first;
            //cout<<i<<' '<<pirmas<<' '<<antras<<' '<<j+1<<endl;
            if(pirmas==antras){
                ans[pirmas*2]=max(ans[pirmas*2], j+1);
            }
            else{
                ans[pirmas*2+1]=max(ans[pirmas*2+1], j+1);
            }
        }
    }
    for(pii i:edges){
        vector<int> newret;
        multiset<int> s;
        for(pii j:ret[i.first]){
            if(j.second!=i.second){
                newret.push_back(j.first);
            }
        }
        for(pii j:ret[i.second]){
            if(j.second!=i.first){
                newret.push_back(j.first);
            }
        }
        sort(newret.rbegin(), newret.rend());
        for(int j=1; j<newret.size(); j++){
            ans[newret[j]*2] = max(ans[newret[j]*2], j+1);
        }
    }

    for(int i=n-1; i>=1; i--){
        ans[i]=max(ans[i], ans[i+1]);
    }
    for(int i=1; i<=n; i++){
        cout<<ans[i]<<' ';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

vector<int> g[500001];
vector<pii> ret[500001];
vector<int> ret2[500001];
vector<pii> maxai[500001];

int ans[500002];

int dfs(int v, int p){
    vector<int> toLeave;

    for(int i:g[v]){
        if(i==p){
            toLeave.push_back(i);
            continue;
        }
        ret[v].push_back({dfs(i, v),i});
        ret2[v].push_back(ret[v].back().first);

        maxai[v].push_back(ret[v].back());
        sort(maxai[v].rbegin(), maxai[v].rend());
        if(maxai[v].size()>2){
            maxai[v].pop_back();
        }
    }
    int cnt = 0;
    if(maxai[v].size()>0&&!(maxai[v].size()==1&&maxai[v][0].second==p)){
        cnt = maxai[v][0].first;
        if(maxai[v][0].second==p){
            cnt=maxai[v][1].first;
        }
    }
    g[v]=toLeave;
    return cnt+1;
}

int ind[500001];
map<int, int> tried[500001];
int newret[500000];
int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n; cin>>n;

    vector<pii> edges;

    for(int i=1; i<=n-1; i++){
        int u, v; cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
        edges.push_back({u,v});
    }
    for(int i=1; i<=n; i++){
        ans[i]=1;
        ans[1] = max(ans[1], (int)g[i].size()+1);
    }

    map<vector<int>, int> mp;

    for(int i=1; i<=n; i++){
        dfs(i,i);
        sort(ret2[i].rbegin(), ret2[i].rend());
        for(int j=1; j<ret2[i].size(); j++){
            int pirmas = ret2[i][j];
            int antras = ret2[i][j-1];
            if(pirmas==antras){
                ans[pirmas*2]=max(ans[pirmas*2], j+1);
            }
            else{
                ans[pirmas*2+1]=max(ans[pirmas*2+1], j+1);
            }
        }
        if(!mp.count(ret2[i])){
            mp[ret2[i]]=mp.size();
            ind[i]=mp.size();
        }
        else{
            ind[i]=mp[ret2[i]];
        }

    }
    for(int i=n-1; i>=1; i--){
        ans[i]=max(ans[i], ans[i+1]);
    }
    for(pii i:edges){
        int pirmas = ind[i.first];
        int antras = ind[i.second];
        if(tried[pirmas].count(antras)){
            continue;
        }
        tried[pirmas][antras]=1;
        tried[antras][pirmas]=1;
        int cnt = 0;

        for(pii j:ret[i.first]){
            if(j.second!=i.second){
                newret[cnt]=j.first;
                cnt++;
            }
        }
        for(pii j:ret[i.second]){
            if(j.second!=i.first){
                newret[cnt]=j.first;
                cnt++;
            }
        }
        sort(newret, newret+cnt, greater<int>());
        for(int j=1; j<cnt; j++){
            ans[newret[j]*2] = max(ans[newret[j]*2], j+1);
        }
    }

    for(int i=n-1; i>=1; i--){
        ans[i]=max(ans[i], ans[i+2]);
    }
    for(int i=1; i<=n; i++){
        cout<<ans[i]<<' ';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

vector<int> g[500001];
vector<pii> ret[500001];
vector<int> ret2[500001];
vector<pii> maxai[500001];

int ans[500002];

int dfs(int v, int p){
    vector<int> toLeave;

    for(int i:g[v]){
        if(i==p){
            toLeave.push_back(i);
            continue;
        }
        ret[v].push_back({dfs(i, v),i});
        ret2[v].push_back(ret[v].back().first);

        maxai[v].push_back(ret[v].back());
        sort(maxai[v].rbegin(), maxai[v].rend());
        if(maxai[v].size()>2){
            maxai[v].pop_back();
        }
    }
    int cnt = 0;
    if(maxai[v].size()>0&&!(maxai[v].size()==1&&maxai[v][0].second==p)){
        cnt = maxai[v][0].first;
        if(maxai[v][0].second==p){
            cnt=maxai[v][1].first;
        }
    }
    g[v]=toLeave;
    return cnt+1;
}

int ind[500001];
unordered_map<int, int, custom_hash> tried[500001];

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n; cin>>n;

    vector<pii> edges;

    for(int i=1; i<=n-1; i++){
        int u, v; cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
        edges.push_back({u,v});
    }
    for(int i=1; i<=n; i++){
        ans[i]=1;
        ans[1] = max(ans[1], (int)g[i].size()+1);
    }

    map<vector<int>, int> mp;

    for(int i=1; i<=n; i++){
        dfs(i,i);
        sort(ret2[i].rbegin(), ret2[i].rend());
        for(int j=1; j<ret2[i].size(); j++){
            int pirmas = ret2[i][j];
            int antras = ret2[i][j-1];
            if(pirmas==antras){
                ans[pirmas*2]=max(ans[pirmas*2], j+1);
            }
            else{
                ans[pirmas*2+1]=max(ans[pirmas*2+1], j+1);
            }
        }
        if(!mp.count(ret2[i])){
            mp[ret2[i]]=mp.size();
        }

    }
    for(int i=1; i<=n; i++){
        ind[i] = mp[ret2[i]];
    }
    for(int i=n-1; i>=1; i--){
        ans[i]=max(ans[i], ans[i+1]);
    }
    for(pii i:edges){
        int pirmas = ind[i.first];
        int antras = ind[i.second];
        if(tried[pirmas].count(antras)){
            continue;
        }
        tried[pirmas][antras]=1;
        tried[antras][pirmas]=1;
        vector<int> newret;
        for(pii j:ret[i.first]){
            if(j.second!=i.second){
                newret.push_back(j.first);
            }
        }
        for(pii j:ret[i.second]){
            if(j.second!=i.first){
                newret.push_back(j.first);
            }
        }
        sort(newret.rbegin(), newret.rend());
        for(int j=1; j<newret.size(); j++){
            ans[newret[j]*2] = max(ans[newret[j]*2], j+1);
        }
    }

    for(int i=n-1; i>=1; i--){
        ans[i]=max(ans[i], ans[i+2]);
    }
    for(int i=1; i<=n; i++){
        cout<<ans[i]<<' ';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

vector<int> g[500001];
vector<pii> ret[500001];
vector<pii> maxai[500001];

int ans[500002];

int dfs(int v, int p){
    vector<int> toLeave;

    for(int i:g[v]){
        if(i==p){
            toLeave.push_back(i);
            continue;
        }
        ret[v].push_back({dfs(i, v),i});
        maxai[v].push_back(ret[v].back());
        sort(maxai[v].rbegin(), maxai[v].rend());
        if(maxai[v].size()>2){
            maxai[v].pop_back();
        }
    }
    int cnt = 0;
    if(maxai[v].size()>0&&!(maxai[v].size()==1&&maxai[v][0].second==p)){
        cnt = maxai[v][0].first;
        if(maxai[v][0].second==p){
            cnt=maxai[v][1].first;
        }
    }
    g[v]=toLeave;
    return cnt+1;
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n; cin>>n;

    vector<pii> edges;

    for(int i=1; i<=n-1; i++){
        int u, v; cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
        edges.push_back({u,v});
    }
    for(int i=1; i<=n; i++){
        ans[i]=1;
        ans[1] = max(ans[1], (int)g[i].size()+1);
    }
    for(int i=1; i<=n; i++){
        dfs(i,i);
        sort(ret[i].rbegin(), ret[i].rend());
        for(int j=1; j<ret[i].size(); j++){
            int pirmas = ret[i][j].first;
            int antras = ret[i][j-1].first;
            //cout<<i<<' '<<pirmas<<' '<<antras<<' '<<j+1<<endl;
            if(pirmas==antras){
                ans[pirmas*2]=max(ans[pirmas*2], j+1);
            }
            else{
                ans[pirmas*2+1]=max(ans[pirmas*2+1], j+1);
            }
        }
    }
    for(int i=n-1; i>=1; i--){
        ans[i]=max(ans[i], ans[i+1]);
    }
    for(pii i:edges){
        vector<int> newret;
        multiset<int> s;
        for(pii j:ret[i.first]){
            if(j.second!=i.second){
                newret.push_back(j.first);
            }
        }
        for(pii j:ret[i.second]){
            if(j.second!=i.first){
                newret.push_back(j.first);
            }
        }
        sort(newret.rbegin(), newret.rend());
        for(int j=1; j<newret.size(); j++){
            ans[newret[j]*2] = max(ans[newret[j]*2], j+1);
        }
    }

    for(int i=n-1; i>=1; i--){
        ans[i]=max(ans[i], ans[i+2]);
    }
    for(int i=1; i<=n; i++){
        cout<<ans[i]<<' ';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

vector<int> g[500001];
vector<pii> ret[500001];
vector<pii> maxai[500001];

int ans[500002];

int dfs(int v, int p){
    vector<int> toLeave;

    for(int i:g[v]){
        if(i==p){
            toLeave.push_back(i);
            continue;
        }
        ret[v].push_back({dfs(i, v),i});
        maxai[v].push_back(ret[v].back());
        sort(maxai[v].rbegin(), maxai[v].rend());
        if(maxai[v].size()>2){
            maxai[v].pop_back();
        }
    }
    int cnt = 0;
    if(maxai[v].size()>0&&!(maxai[v].size()==1&&maxai[v][0].second==p)){
        cnt = maxai[v][0].first;
        if(maxai[v][0].second==p){
            cnt=maxai[v][1].first;
        }
    }
    g[v]=toLeave;
    return cnt+1;
}

int main()
{
    int n; cin>>n;

    vector<pii> edges;

    for(int i=1; i<=n-1; i++){
        int u, v; cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
        edges.push_back({u,v});
    }
    for(int i=1; i<=n; i++){
        ans[i]=1;
        ans[1] = max(ans[1], (int)g[i].size()+1);
    }
    for(int i=1; i<=n; i++){
        dfs(i,i);
        sort(ret[i].rbegin(), ret[i].rend());
        for(int j=1; j<ret[i].size(); j++){
            int pirmas = ret[i][j].first;
            int antras = ret[i][j-1].first;
            //cout<<i<<' '<<pirmas<<' '<<antras<<' '<<j+1<<endl;
            if(pirmas==antras){
                ans[pirmas*2]=max(ans[pirmas*2], j+1);
            }
            else{
                ans[pirmas*2+1]=max(ans[pirmas*2+1], j+1);
            }
        }
    }
    for(int i=n-1; i>=1; i--){
        ans[i]=max(ans[i], ans[i+1]);
    }
    for(pii i:edges){
        vector<int> newret;
        multiset<int> s;
        for(pii j:ret[i.first]){
            if(j.second!=i.second){
                newret.push_back(j.first);
            }
        }
        for(pii j:ret[i.second]){
            if(j.second!=i.first){
                newret.push_back(j.first);
            }
        }
        sort(newret.rbegin(), newret.rend());
        for(int j=1; j<newret.size(); j++){
            ans[newret[j]*2] = max(ans[newret[j]*2], j+1);
        }
    }

    for(int i=n-1; i>=1; i--){
        ans[i]=max(ans[i], ans[i+2]);
    }
    for(int i=1; i<=n; i++){
        cout<<ans[i]<<' ';
    }
    return 0;
}