/*
   Author A.G.Maruf
   7 th sem :P
   code written 07:16 PM; 17 March 2019
*/
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cctype>
#define gc              getchar
#define pc              putchar
#define pb              push_back
#define Sort_arr(n,x)   sort(n,n+x);
#define Sortr_arr(arr,x)  sort(arr, arr+n,greater<int>());
#define SortS(s)        sort(s.begin(), s.end());
#define SortRS(s)       sort(s.rbegin(), s.rend());
#define all(s)          s.begin(), s.end()a
#define GCin(a)         getline(cin,a);
#define Sz(a)           a.size()
#define arr_rev(n)      sort(n.begin(), n.end(), greater<int>());
#define Gin(a)          getline(cin,a);
#define input(a)        scanf("%d",&a);
#define Sz(a)           a.size()
#define input2(a,b)     scanf("%d %d",&a,&b);
#define input3(a,b,c)   scanf("%d %d %d",&a,&b,&c);
#define input4(a,b,c,d) cin>>a>>b>>c>>d;
#define rep(n)          for(int i=1;i<n;i++)
#define Fast_read       ios_base::sync_with_stdio(false);
#define Unique(n)       sort(Search(n)),n.erase(unique(Search(n)),n.end());
#define PI              3.1415926535897932384626433832795l
#define Ignore          cin.ignor3e();
#define out(n)          cout<<n<<endl;
#define mem(n,i)        memset(n,i,sizeof n);
#define square(n)       (n*n)
#define cube(n)         (n*n*n)
#define F               first
#define S               second
#define mxin            -INFINITY
#define mnin            INFINITY
#define el              <<endl
#define MAXC 1000
//#define N 1000000
using namespace std;

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/
//ll gcd(ll a,ll b){while(b){ll x=a%b;a=b;b=x;}return a;}
//ll lcm(ll a,ll b){return a/__gcd(a,b)*b;}
//ll qpow(ll n,ll k) {ll ans=1;assert(k>=0);n%=mod;while(k>0){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans%mod;}

typedef long long int ll;
typedef pair <ll, ll> pll;
const int Max = 1e4 + 10;
const int MOD = 1e9 + 7;

struct custom{
	int ans;
	int val;
	int pos;
};
bool comp(custom a,custom b){
		return a.val<b.val;
}
bool comp1(custom a,custom b){
	return a.pos<b.pos;
}
int main (){
	int n;
	cin>>n;
	int arr[n+5];
	custom brr[n+5];
	for (int i=0;i<n;i++){
		cin>>arr[i];
	}
	for (int i=0;i<n;i++){
		cin>>brr[i].val;
		brr[i].pos=i;
	}
	sort (brr,brr+n,comp);
	sort(arr,arr+n,greater<int>());
	for (int i=0;i<n;i++){
		//brr[i].s=i;
		brr[i].ans=arr[i];
	}
	sort(brr,brr+n,comp1);
	for (int i=0;i<n;i++)cout<<brr[i].ans<<" ";
	cout<<endl;
}


/*
   Author A.G.Maruf
   7 th sem :P
   code written 09:30 PM; 6 March 2019
*/
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cctype>
#define gc              getchar
#define pc              putchar
#define pb              push_back
#define Sort_arr(n,x)   sort(n,n+x);
#define Sortr_arr(arr,x)  sort(arr, arr+n,greater<int>());
#define SortS(s)        sort(s.begin(), s.end());
#define SortRS(s)       sort(s.rbegin(), s.rend());
#define all(s)          s.begin(), s.end()a
#define GCin(a)         getline(cin,a);
#define Sz(a)           a.size()
#define arr_rev(n)      sort(n.begin(), n.end(), greater<int>());
#define Gin(a)          getline(cin,a);
#define input(a)        scanf("%d",&a);
#define Sz(a)           a.size()
#define input2(a,b)     scanf("%d %d",&a,&b);
#define input3(a,b,c)   scanf("%d %d %d",&a,&b,&c);
#define input4(a,b,c,d) cin>>a>>b>>c>>d;
#define rep(n)          for(int i=1;i<n;i++)
#define Fast_read       ios_base::sync_with_stdio(false);
#define Unique(n)       sort(Search(n)),n.erase(unique(Search(n)),n.end());
#define PI              3.1415926535897932384626433832795l
#define Ignore          cin.ignor3e();
#define out(n)          cout<<n<<endl;
#define mem(n,i)        memset(n,i,sizeof n);
#define square(n)       (n*n)
#define cube(n)         (n*n*n)
#define F               first
#define S               second
#define mxin            -INFINITY
#define mnin            INFINITY
#define el              <<endl
#define MAXC 1000
//#define N 1000000
using namespace std;

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/
//ll gcd(ll a,ll b){while(b){ll x=a%b;a=b;b=x;}return a;}
//ll lcm(ll a,ll b){return a/__gcd(a,b)*b;}
//ll qpow(ll n,ll k) {ll ans=1;assert(k>=0);n%=mod;while(k>0){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans%mod;}

//typedef pair <ll, ll> pll;
typedef long long int ll;
const int Max = 1e4 + 10;
const int MOD = 1e9 + 7;

int main (){
	Fast_read
	int n;
	cin>>n;
	int arr[n+5];
	int brr[n+5];
	for (int i=0;i<n;i++){
		cin>>arr[i];
		cin>>brr[i];
	}
	for(int i=0;i<n;i++){
		cout<<arr[i]<<" ";
	}
	cout<<endl;
}


/*
   Author A.G.Maruf
   7 th sem :P
   code written 09:30 PM; 6 March 2019
*/
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cctype>
#define gc              getchar
#define pc              putchar
#define pb              push_back
#define Sort_arr(n,x)   sort(n,n+x);
#define Sortr_arr(arr,x)  sort(arr, arr+n,greater<int>());
#define SortS(s)        sort(s.begin(), s.end());
#define SortRS(s)       sort(s.rbegin(), s.rend());
#define all(s)          s.begin(), s.end()a
#define GCin(a)         getline(cin,a);
#define Sz(a)           a.size()
#define arr_rev(n)      sort(n.begin(), n.end(), greater<int>());
#define Gin(a)          getline(cin,a);
#define input(a)        scanf("%d",&a);
#define Sz(a)           a.size()
#define input2(a,b)     scanf("%d %d",&a,&b);
#define input3(a,b,c)   scanf("%d %d %d",&a,&b,&c);
#define input4(a,b,c,d) cin>>a>>b>>c>>d;
#define rep(n)          for(int i=1;i<n;i++)
#define Fast_read       ios_base::sync_with_stdio(false);
#define Unique(n)       sort(Search(n)),n.erase(unique(Search(n)),n.end());
#define PI              3.1415926535897932384626433832795l
#define Ignore          cin.ignor3e();
#define out(n)          cout<<n<<endl;
#define mem(n,i)        memset(n,i,sizeof n);
#define square(n)       (n*n)
#define cube(n)         (n*n*n)
#define F               first
#define S               second
#define mxin            -INFINITY
#define mnin            INFINITY
#define el              <<endl
#define MAXC 1000
//#define N 1000000
using namespace std;

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/
//ll gcd(ll a,ll b){while(b){ll x=a%b;a=b;b=x;}return a;}
//ll lcm(ll a,ll b){return a/__gcd(a,b)*b;}
//ll qpow(ll n,ll k) {ll ans=1;assert(k>=0);n%=mod;while(k>0){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans%mod;}

//typedef pair <ll, ll> pll;
typedef long long int ll;
const int Max = 1e4 + 10;
const int MOD = 1e9 + 7;

int main (){
	Fast_read
	int n;
	cin>>n;
	int arr[n+5];
	int brr[n+5];
	for (int i=0;i<n;i++){
		cin>>arr[i];
	}
	for (int i=0;i<n;i++)cin>>brr[i];
	sort(arr,arr+n);
	for(int i=0;i<n;i++){
		cout<<arr[i]<<" ";
	}
	cout<<endl;
}


/*
   Author A.G.Maruf
   7 th sem :P
   code written 09:30 PM; 6 March 2019
*/
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cctype>
#define gc              getchar
#define pc              putchar
#define pb              push_back
#define Sort_arr(n,x)   sort(n,n+x);
#define Sortr_arr(arr,x)  sort(arr, arr+n,greater<int>());
#define SortS(s)        sort(s.begin(), s.end());
#define SortRS(s)       sort(s.rbegin(), s.rend());
#define all(s)          s.begin(), s.end()a
#define GCin(a)         getline(cin,a);
#define Sz(a)           a.size()
#define arr_rev(n)      sort(n.begin(), n.end(), greater<int>());
#define Gin(a)          getline(cin,a);
#define input(a)        scanf("%d",&a);
#define Sz(a)           a.size()
#define input2(a,b)     scanf("%d %d",&a,&b);
#define input3(a,b,c)   scanf("%d %d %d",&a,&b,&c);
#define input4(a,b,c,d) cin>>a>>b>>c>>d;
#define rep(n)          for(int i=1;i<n;i++)
#define Fast_read       ios_base::sync_with_stdio(false);
#define Unique(n)       sort(Search(n)),n.erase(unique(Search(n)),n.end());
#define PI              3.1415926535897932384626433832795l
#define Ignore          cin.ignor3e();
#define out(n)          cout<<n<<endl;
#define mem(n,i)        memset(n,i,sizeof n);
#define square(n)       (n*n)
#define cube(n)         (n*n*n)
#define F               first
#define S               second
#define mxin            -INFINITY
#define mnin            INFINITY
#define el              <<endl
#define MAXC 1000
//#define N 1000000
using namespace std;

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/
//ll gcd(ll a,ll b){while(b){ll x=a%b;a=b;b=x;}return a;}
//ll lcm(ll a,ll b){return a/__gcd(a,b)*b;}
//ll qpow(ll n,ll k) {ll ans=1;assert(k>=0);n%=mod;while(k>0){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans%mod;}

//typedef pair <ll, ll> pll;
typedef long long int ll;
const int Max = 1e4 + 10;
const int MOD = 1e9 + 7;

int main (){
	Fast_read
	int n;
	cin>>n;
	int arr[n+5];
	int brr[n+5];
	for (int i=0;i<n;i++){
		cin>>arr[i];
	}
	for (int i=0;i<n;i++)cin>>brr[i];
	//sort(arr,arr+n);
	for(int i=0;i<n;i++){
		cout<<arr[i]<<" ";
	}
	cout<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main(){

int m;
cin>>m;
int a[m],b[m],res[m];
vector< pair < int , int > >pr[m];
for(int i=0;i<m;i++)cin>>a[i];

for(int i=0;i<m;i++){
	cin>>b[i];
	pr[i].first=b[i];
	pr[i].second=i;
}
	sort(a,a+m);
sort(pr.begin(),pr.end());
reverse(pr.begin(),pr.end());
for(int i=0;i<m;i++){
	res[pr.second]=a[i];
}
for(int i=0;i<m;i++)cout<<res[i];

return 0;}


#include<bits/stdc++.h>
using namespace std;
int main(){

int m;
cin>>m;
int a[m],b[m],res[m];
vector< pair < int , int > >pr(m);
for(int i=0;i<m;i++)cin>>a[i];

for(int i=0;i<m;i++){
	cin>>b[i];
	pr[i]= make_pair(b[i],i);
}
	sort(a,a+m);
sort(pr.begin(),pr.end());
reverse(pr.begin(),pr.end());
for(int i=0;i<m;i++){
	res[pr[i].second]=a[i];
}
for(int i=0;i<m;i++)cout<<res[i]<<" ";

return 0;}


#include<bits/stdc++.h>
using namespace std;
int main(){

int m;
cin>>m;
int a[m],b[m],res[m];
vector< pair < int , int > >pr(m);
for(int i=0;i<m;i++)cin>>a[i];

for(int i=0;i<m;i++){
	cin>>b[i];
	pr[i]= make_pair(b[i],i);
}
	sort(a,a+m);
sort(pr.begin(),pr.end());
reverse(pr.begin(),pr.end());
for(int i=0;i<m;i++){
	res[pr[i].second]=a[i];
}
for(int i=0;i<m;i++)cout<<res[i];

return 0;}


#include<bits/stdc++.h>
using namespace std;
int main(){

int m;
cin>>m;
int a[m],b[m],res[m];
vector< pair < int , int > >pr[m];
for(int i=0;i<m;i++)cin>>a[i];

for(int i=0;i<m;i++){
	cin>>b[i];
	pr[i]= make_pair(b[i],i);
}
	sort(a,a+m);
sort(pr.begin(),pr.end());
reverse(pr.begin(),pr.end());
for(int i=0;i<m;i++){
	res[pr.second]=a[i];
}
for(int i=0;i<m;i++)cout<<res[i];

return 0;}


#include <bits/stdc++.h>

using namespace std;

const int nmax=2e5+5;

pair<int,int>v[nmax];
int f[nmax],ans[nmax];

int main()
{
    long long n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>f[i];
    for(int i=1;i<=n;i++)
    {
        cin>>v[i].first;
        v[i].second=i;
    }
    sort(f+1,f+n+1);
    reverse(f+1,f+n+1);
    sort(v+1,v+n+1);
    for(int i=1;i<=n;i++)
        ans[v[i].second]=f[i];
    for(int i=1;i<=n;i++)
        cout<<ans[i]<<" ";
    return 0;
}


#pragma GCC optimize ("O3")

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <tuple>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <math.h>
#include <numeric>
#include <functional>
#include <limits>
#include <sstream>
#include <fstream>

#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define cont(a) (a).begin(), (a).end()
#define get1(x) get<0>(x)
#define get2(x) get<1>(x)
#define get3(x) get<2>(x)
#define heap priority_queue
#define hash_set unordered_set
#define hash_map unordered_map

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll inf = numeric_limits<ll>::max() / 2;
const ld eps = 1e-9;

ll N;
vector<ll> a;
vector<pll> b;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	a.resize(N);
	for (ll i = 0; i < N; i++) {
		cin >> a[i];
	}
	b.resize(N);
	for (ll i = 0; i < N; i++) {
		cin >> b[i].first;
		b[i].second = i;
	}
	sort(cont(a));
	sort(cont(b));
	vector<ll> ans(N);
	for (ll i = 0; i < N; i++) {
		ans[b[i].second] = a[i];
	}
	for_each(cont(ans), [](ll el) {cout << el << " "; });
	cout << endl;
	return 0;
}


#pragma GCC optimize ("O3")

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <tuple>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <math.h>
#include <numeric>
#include <functional>
#include <limits>
#include <sstream>
#include <fstream>

#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define cont(a) (a).begin(), (a).end()
#define get1(x) get<0>(x)
#define get2(x) get<1>(x)
#define get3(x) get<2>(x)
#define heap priority_queue
#define hash_set unordered_set
#define hash_map unordered_map

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll inf = numeric_limits<ll>::max() / 2;
const ld eps = 1e-9;

ll N;
vector<ll> a;
vector<pll> b;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	a.resize(N);
	for (ll i = 0; i < N; i++) {
		cin >> a[i];
	}
	b.resize(N);
	for (ll i = 0; i < N; i++) {
		cin >> b[i].first;
		b[i].second = i;
	}
	sort(cont(a));
	sort(cont(b));
	vector<ll> ans(N);
	for (ll i = 0; i < N; i++) {
		ans[b[i].second] = a[N - i - 1];
	}
	for_each(cont(ans), [](ll el) {cout << el << " "; });
	cout << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll n;
	cin>>n;
	ll arr[n],tar[n];
	vector<pair<ll,ll> >v,v1;
	ll cnt[n+4];
	for(ll i=0;i<n;i++){
		cin>>arr[i];
		v.push_back(make_pair(arr[i],i));
	}
	for(ll i=0;i<n;i++){
		cin>>tar[i];
		v1.push_back(make_pair(tar[i],i));
	}
	sort(v.rbegin(), v.rend());
	sort(v1.begin(), v1.end());
	for(ll i=0;i<n;i++)
	{
		cnt[v1[i].second]=v[i].first;
	}
	for(int i=0;i<n;i++)
		cout<<cnt[i]<<" ";
	cout<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> > p;
int v[10000];
int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++){cin >> a[i];}
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        p.push_back({x,i});
    }
    sort(p.rbegin(),p.rend());
    sort(a,a+n);
    for(int i=0;i<n;i++){
        v[p[i].second]=a[i];
    }
    for(int i=0;i<n;i++){
        cout << v[i] << " ";
    }
}


#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> > p;
int v[200010];
int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++){cin >> a[i];}
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        p.push_back({x,i});
    }
    sort(p.rbegin(),p.rend());
    sort(a,a+n);
    for(int i=0;i<n;i++){
        v[p[i].second]=a[i];
    }
    for(int i=0;i<n;i++){
        cout << v[i] << " ";
    }
}


#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> > p;
vector<int>v;
int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++){cin >> a[i];}
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        p.push_back({x,i});
    }
    sort(p.rbegin(),p.rend());
    sort(a,a+n);
    for(int i=0;i<n;i++){
        v.push_back(p[i].second=a[i]);
    }
    for(int i=0;i<n;i++){
        cout << v[i] << " ";
    }
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
using namespace std;
#define int long long
#define fi(i,a,b) for(int i = a; i < (b) ;i++)
const int N = 200005;

struct node { int x, index; };
node b[N];
int a[N];
int res[N];
bool comp(node a, node b) { return a.x > b.x; }
void main() {
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n; cin >> n;
	fi(i, 0, n) { cin >> a[i]; }
	fi(i, 0, n) { cin >> b[i].x; b[i].index = i; }
	sort(a, a + n);
	sort(b, b + n, comp);
	fi(i, 0, n) { res[b[i].index] = a[i]; }
	fi(i, 0, n) {
		cout << res[i]<<" ";
	}
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define out(a) printf("%d ",a)
#define ll long long
using namespace std;
struct dist
{
	int l,r;
}a[200005],b[200005];
int ans[200005];
int hh[200005];
bool cmp(dist a,dist b)
{
	return a.l>b.l;
}
bool cmps(dist a,dist b)
{
	return a.l<b.l;
}
int n;
int i;
int main()
{
	in(n);
	for (i=1;i<=n;i++) {
	  in(a[i].l); hh[i]=a[i].l;
	  a[i].r=i;
     }
	for (i=1;i<=n;i++) {
	  in(b[i].l);
	  b[i].r=i;
     }
	sort(b+1,b+n+1,cmp);
	sort(a+1,a+n+1,cmps);
	for (i=1;i<=n;i++)
	  ans[b[i].r]=hh[a[i].r];
	  //out(a[i].r);
	  //cout<<endl;
	for (i=1;i<=n;i++)
	  out(ans[i]);
}


#include<iostream>
using namespace std;
#include<string>
#include<string.h>
#include<algorithm>

struct Node
{
	int pos;
	int value;
};

bool cmp(Node &a, Node &b)
{
	return a.value > b.value;
}

int main()
{
	int m;
	while (scanf("%d",&m)!=EOF)
	{
		int a[200005];
		int b[200005];
		int i;
		for (i = 0; i < m; i++)
			scanf("%d", &a[i]);
		for (i = 0; i < m; i++)
			scanf("%d", &b[i]);
		Node c[200005];
		for (i = 0; i < m; i++)
		{
			c[i].pos = i;
			c[i].value = b[i];
		}
		sort(a, a + m);
		sort(c, c + m, cmp);
		int pr[200005];
		for (i = 0; i < m; i++)
		{
			pr[c[i].pos] = a[i];
		}
		for (i = 0; i < m; i++)
			cout << pr[i] << " ";
		cout << endl;

	}
	return 0;
}


#include <vector>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <iomanip>
using namespace std;
const long INF = 2e9;

int main()
{
#ifdef MY_DEBUG
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
#endif

  int m = 0;
  cin >> m;
  vector<pair<int, int>> a(m), b(m);
  int t = 0;
  for(int i = 0; i < m; i++)
  {
    cin >> t;
    a[i] = pair<int,int>(t,i);
  }

  for(int i = 0; i < m; i++)
  {
    cin >> t;
    b[i] = pair<int,int>(t, i);
  }

  sort(a.begin(), a.end());
  sort(b.rbegin(), b.rend());

  vector<int> c(m);

  for(int i = 0 ; i < m; i++)
  {
    c[b[i].second] = a[i].first;
  }

  for(int i = 0 ; i < m; i++)
  {
    cout << c[i] << " ";
  }

  return 0;
}


#include <iostream>
#include <cstring>
#include<algorithm>
#define N 200007

using namespace std;
int a[N];
struct pos{
	int B;
	int p;
};
pos b[N];
int c[N];
int m;
bool cmp(pos a, pos b)
{
	return a.B>b.B;
}
int main()
{
	cin>>m;
	for(int i=1;i<=m;i++)
	 scanf("%d",&a[i]);
	 for(int i=1;i<=m;i++)
	{
	  scanf("%d",&b[i].B);
	  b[i].p=i;
    }
	 sort(a+1,a+m+1);
	  sort(b+1,b+m+1,cmp);
	  for(int i=1;i<=m;i++)
	  {
	  	c[b[i].p]=a[i];
	   }
	   for(int i=1;i<=m;i++)
	   printf("%d ",c[i]);

	   printf("\n");
	return 0;
 }


#include "iostream"
#include "algorithm"
using namespace std;
struct MyStruct
{
	int num,flag;
}b[200007];
bool cmp1(MyStruct a, MyStruct b)
{
	if (a.num == b.num)
		return a.flag > b.flag;
	return a.num < b. num;
}
bool cmp2(MyStruct a, MyStruct b)
{
	return a.flag < b.flag;
}
int main()
{
	int a[200007], n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
	{
		cin >> b[i].num;
		b[i].flag = i;
	}
	sort(a, a + n);
	sort(b, b + n, cmp1);
	for (int i = 0; i < n; i++)
		b[i].num = a[n - i - 1];
	sort(b, b + n, cmp2);
	for (int i = 0; i < n-1; i++)
		cout << b[i].num << " ";
	cout << b[n - 1].num << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <utility>
#include <algorithm>
#include <map>
#include <climits>
#include <string>
#include <cstring>
#include <fstream>
#include <queue>
#include <set>
#include<functional>
#include<iomanip>
using namespace std;
typedef long long ll;
map<int, vector<int>>m;
bool sortDes(int a, int b){
	return a > b;
}
int main()
{
	int n, tmp;
	cin >> n;
	int* a = new int[n];
	int* b = new int[n];
	int* b1 = new int[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++){
		cin >> tmp;
		b[i] = tmp;
		b1[i] = tmp;
	}
	sort(a, a + n,sortDes);
	sort(b, b + n);
	for (int i = 0; i < n; i++){
		m[b[i]].push_back(a[i]);
	}
	for (int i = 0; i < n; i++){
		cout << m[b1[i]][0] << ' ';
		m[b1[i]].erase(m[b1[i]].begin());
	}
	cout << endl;
	//system("pause");
	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <utility>
#include <algorithm>
#include <map>
#include <climits>
#include <string>
#include <cstring>
#include <fstream>
#include <queue>
#include <set>
#include<functional>
#include<iomanip>
using namespace std;
typedef long long ll;
map<int, vector<int>>m;
bool sortDes(int a, int b){
	return a > b;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, tmp;
	cin >> n;
	int* a = new int[n];
	int* b = new int[n];
	int* b1 = new int[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++){
		cin >> tmp;
		b[i] = tmp;
		b1[i] = tmp;
	}
	sort(a, a + n, sortDes);
	sort(b, b + n);
	for (int i = 0; i < n; i++){
		m[b[i]].push_back(a[i]);
	}
	for (int i = 0; i < n; i++){
		printf("%d ",m[b1[i]][0]);
		m[b1[i]].erase(m[b1[i]].begin());
	}
	cout << endl;
	//system("pause");
	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <utility>
#include <algorithm>
#include <map>
#include <climits>
#include <string>
#include <cstring>
#include <fstream>
#include <queue>
#include <set>
#include<functional>
#include<iomanip>
using namespace std;
typedef long long ll;
map<int, stack<int>>m;
bool sortDes(int a, int b){
	return a > b;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, tmp;
	cin >> n;
	int* a = new int[n];
	int* b = new int[n];
	int* b1 = new int[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++){
		cin >> tmp;
		b[i] = tmp;
		b1[i] = tmp;
	}
	sort(a, a + n, sortDes);
	sort(b, b + n);
	for (int i = 0; i < n; i++){
		m[b[i]].push(a[i]);
	}
	for (int i = 0; i < n; i++){
		printf("%d ", m[b1[i]].top());
		m[b1[i]].pop();
	}
	cout << endl;
	//system("pause");
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <memory.h>
#include <set>

using namespace std;

// Input macros
#define s(n)                        scanf("%d",&n)
#define sl(n)						scanf("%I64d", &n)
#define sc(n)                       scanf("%c",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)

// Useful container manipulation / traversal macros
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair

typedef vector<int> vi;
typedef vector<string> vs;

#define INF 2147483647
#define UINF 0xffffffff

#define N 200000+10
multiset<int> a;
struct dd
{
	int i, data, a;
}b[N];

bool sortb(dd &lhs, dd &rhs)
{
	return lhs.data > rhs.data;
}

bool sorti(dd &lhs, dd &rhs)
{
	return lhs.i < rhs.i;
}

int main()
{
	int n;
	s(n);
	forall(i, 0, n)
	{
		int temp;
		s(temp);
		a.insert(temp);
	}
	forall(i, 0, n)
	{
		s(b[i].data);
		b[i].i = i;
	}
	sort(b, b+n, sortb);

	forall(i, 0, n)
	{
		multiset<int>::iterator it = a.lower_bound(b[i].data);
		b[i].a = *it;
		a.erase(it);
	}
	sort(b, b + n, sorti);

	forall(i, 0, n)
		printf("%d ", b[i].a);
}


#include <iostream>
#include <algorithm>
using namespace std;

int m;
const int MAXM = 200005;
int A[MAXM], finalA[MAXM];
pair<int, int> B[MAXM];

int main()
{
	cin >> m;
	for (int i = 0; i < m; i++)
		cin >> A[i];
	for (int i = 0; i < m; i++)
	{
		cin >> B[i].first;
		B[i].second = i;
	}

	sort(B, B + m);
	sort(A, A + m);

	for (int i = m - 1; i >= 0; i--)
	{
		int x = B[m - 1 - i].second;
		finalA[x] = A[i];
	}

	for (int i = 0; i < m; i++)
		cout << finalA[i] << " ";

	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<iostream>
using namespace std;
const int MAXN=200010;
struct Node
{
	int pnt,num;
};
Node a[MAXN],b[MAXN];

int cmp(Node x,Node y)
{
	return x.pnt<y.pnt;
}

int cmp1(Node x,Node y)
{
	return x.num<y.num;
}

int cmp2(Node x,Node y)
{
	return x.pnt>y.pnt;
}

int main()
{
	int i,j,k,l,m,n;

	scanf("%d",&n);

	for (i=1;i<=n;i++)
	{
		scanf("%d",&a[i].pnt);
		a[i].num=i;
	}
	sort(a+1,a+1+n,cmp2);

	for (i=1;i<=n;i++)
	{
		scanf("%d",&b[i].pnt);
		b[i].num=i;
	}
	sort(b+1,b+1+n,cmp);

	for (i=1;i<=n;i++)
	{
		a[i].num=b[i].num;
	}
	sort(a+1,a+1+n,cmp1);

	for (i=1;i<=n;i++)
	{
		printf("%d ",a[i].pnt);
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <iostream>
#include <deque>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <map>
#include <algorithm>
#include <functional>
#include <set>
#include <numeric>
#include <limits>
#include <ctime>
#include <cassert>
#include <sstream>
#include <bitset>
#include <unordered_set>
#include <unordered_map>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define all(x) x.begin(), x.end()
#define mp make_pair
#define PI acos(-1.0)

using namespace std;

template<typename T> istream& operator>> (istream &in, vector<T> &a) {
	for (int i = 0; i < a.size(); ++i)
		in >> a[i];
	return in;
}

template<typename T> ostream& operator<< (ostream &out, const vector<T> &a) {
	for (int i = 0; i < a.size(); ++i)
		out << a[i] << " ";
	return out;
}

void solve() {
  int n;
  cin >> n;
  vector<int> a(n), c(n);
  vector< pair<int, int> > b(n);
  cin >> a;
  for (int i = 0; i < n; ++i) {
    cin >> b[i].first;
    b[i].second = i;
  }
  sort(all(a), greater<int>());
  sort(all(b));
  for (int i = 0; i < n; ++i) {
    c[b[i].second] = a[i];
  }
  cout << c << endl;
}

#define name "segmentupdate"

int main(int argc, char* argv[]) {
	ios_base::sync_with_stdio(false);
	//freopen(name ".in", "r", stdin), freopen(name ".out", "w", stdout);
	//freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
	cout.setf(ios::fixed);
	cout.precision(8);
	solve();
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

const int N = 2e5 + 100;
int a[N],b[N];
struct node
{
    int x,y;
} tree[N];

bool cmp(int x, int y)
{
    return x>y;
}

bool cmp1(node x, node y)
{
    return x.x<y.x;
}

bool cmp2(node x, node y)
{
    return x.y<y.y;
}

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=0; i<n; i++)
            scanf("%d",a+i);
        for(int i=0; i<n; i++)
        {
            scanf("%d",&tree[i].x);
            tree[i].y = i;
        }
        sort(a,a+n,cmp);
//        for(int i=0; i<n; i++)
//            printf("%d ",a[i]);
//        printf("\n");
        sort(tree,tree+n,cmp1);
//        for(int i=0; i<n; i++)
//            printf("%d ",tree[i].x);
//        printf("\n");
//        for(int i=0; i<n; i++)
//            printf("%d ",tree[i].y);
//        printf("\n");
        for(int i=0; i<n; i++)
        {
            tree[i].x = a[i];
        }
        sort(tree,tree+n,cmp2);
        for(int i=0; i<n; i++)
            printf("%d ",tree[i].x);
        printf("\n");
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <sstream>
#include <algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define ft first
#define sd second

const int INF = 1000000000;

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

	vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}

	vector<pair<int, int> > b(n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &b[i].ft);
		b[i].sd = i;
	}

	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	sort(b.begin(), b.end());

	vector<int> ans(n);
	for (int i = 0; i < n; i++)
	{
		ans[b[i].sd] = a[i];
	}

	for (int i = 0; i < n; i++)
		printf("%d ", ans[i]);
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<set>
#include<cctype>
#include<map>
#include<bitset>
#include<iostream>
#include<queue>
#include<stack>
using namespace std;
//cout<<setprecision(3)<<fixed<<sqrt(2*10.0*n)<<endl;
//int asd(long long num,int& y)
//{
//	int x=1,z=1;
//	while(x*2<=num)
//		x*=2,z++;
//	y=num-x;
//	return z;
//}
//int as1(string s)
//{
//    int decimal=0, i=0, rem;
//	int n=s.size()-1;
//    while (n>=0)
//    {
//        rem =s[n]-48;
//        decimal += rem*pow(2.0,i);
//        ++i;
//		n--;
//    }
//    return decimal;
//}
//int r;
//int asd[3];
//int asd1[3];
//int sum1(int x,int y, int z)
//{
//	int x3,y3,z3,sum=0,z4,y4,x4;
//	z4=y3-z3;
//	if(r>=z4*asd1[2])
//	{
//		sum+=z4;
//		r-=(z4*asd1[2]);
//		z4=x3-y3;
//		y4=z4;
//		z3=asd[0]%z;
//		y3=asd[1]%y;
//		if(r>=(z4*asd1[0]+y4*asd1[1]))
//		{
//			sum+=y4;
//			r-=(z4*asd1[0]+y4*asd1[1]);
//			x3=asd[3]%x;
//			if(r>=((x-x3)*asd[2]+(y-y3)*asd[1]+(z-z3)*asd[0]))
//			{
//				r-=((x-x3)*asd[2]+(y-y3)*asd[1]+(z-z3)*asd[0]);
//				sum++;
//				sum+=(r/(x*asd[2]+y*asd[1]+z*asd[0]));
//				return sum;
//			}
//			else
//				return sum;
//		}
//		else
//			return (r/(z4*asd1[0]+y4*asd1[1]))+sum;
//	}
//	else
//		return r/(z4*asd1[2]);
//}

//long long asd1(string s)
//{
//	long long x=0,y=1;
//	for(int i=0;i<s.size();i++,y*=2)
//	{
//		if(s[i]=='0')
//		   x+=y;
//	}
//	return x;
//}
//void asd3(long long n)
//{
//	int i=0;
//	while(n)
//	{
//		if(n%10!=0)
//			i=1,cout<<n%10;
//		else if(i)
//			cout<<n%10;
//		n=n/10;
//	}
//	if(i==0)
//		cout<<0;
//	cout<<endl;
//}
//long long l=10000001;
bool d(string s,string c)
{
	if(s.size()<c.size())
	{
		for(int i=0;i<s.size();i++)
		{
			if(s[i]<c[i])
				return true;
			else if(s[i]>c[i])
				return false;
		}
		return true;
	}
	else
	{for(int i=0;i<c.size();i++)
		{
			if(s[i]<c[i])
				return true;
			else if(s[i]>c[i])
				return false;
		}
		return false;

	}
}
bool cmp(pair<string,int> i,pair<string,int> j)
{
	if(i.second>j.second)
		return true;
	else if(j.second==i.second&&j.first>i.first)
		return true;
	else
		return false;
}
//vector<char>asd;
//string asd2(string s)
//{
//	string c=s;
//	c+='R';
//	for(int i=s.size()-1;i>=0;i--)
//		if(s[i]=='R')
//			c+='L';
//		else
//			c+='R';
//	return c;
//}
//vector<bool>asd(20000000,false);
//vector<int>asd1(20000);
//void asd2()
//{
//	asd[0]=1;
//	asd[1]=1;
//	for(int i=2;i*i<=20000000;i++)
//		if(!asd[i])
//		{
//			for(int j=i*i;j<20000000;j=j+i)
//				asd[j]=true;
//		}
//}
//void asd3()
//{
//	int x=1;
//	for(int i=5;i<20000000;i++)
//		if(asd[i]==0)
//			asd1[x++]=asd[i];
//}
void in_out_txt()
{
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
}
//int n;
//vector<vector<int>>asd;
//bool mak[201];
//void fu()
//{
//	for(int i=0;i<201;i++)
//	{
//		mak[i]=false;
//	}
//}
//bool dfs(int i)
//{
//	if(i==n)
//		return true;
//	mak[i]=true;
//	for(int j=0;j<asd[i].size();j++)
//	{
//		if(mak[asd[i][j]])
//			return false;
//		dfs(asd[i][j]);
//	}
//	return true;
//}
//int n,m,x,y,z,asd[1000]={0},l;
//vector<vector<int>>asd1(1000000);
//void dfs(int i)
//{
//	if(asd[i])
//		return ;
//	asd[i]=1;
//	for(int j=0;j<asd1[i].size();j++)
//		dfs(asd1[i][j]);
//}
//int asd[100000]={0};
//void bob()
//{
//	for(int i=2;i<100000;i++)
//	{
//		if(asd[i]==0)
//		{
//			for(int j=i*2;j<100000;j+=i)
//				asd[j]=1;
//		}
//	}
//}
int main()
{
	//in_out_txt();
	long long asd[200010],asd1[200010],n,x,y,z;
	pair<long long,long long>asd2[200010];
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>asd[i];
	for(int i=0;i<n;i++)
		cin>>asd2[i].first,asd2[i].second=i;
	sort(asd,asd+n);
	sort(asd2,asd2+n);
	for(int i=0;i<n;i++)
	{
		asd1[asd2[i].second]=asd[n-i-1];
	}
	for(int i=0;i<n;i++)
		cout<<asd1[i]<<" ";
	cout<<endl;
//	system("pause");
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
const int maxn = 2e5+5;
const int ff = 0x3f3f3f3f;
typedef struct
{
	int pos;
	int u;
	int d;
}node;

node a[maxn];
int b[maxn];

bool cmp1(node x,node y)
{
	return x.d> y.d;
}

bool cmp2(node x,node y)
{
	return x.pos< y.pos;
}

int main()
{
	int n;
	cin>>n;
	for(int i = 1;i<= n;i++)
	{
		scanf("%d",&b[i]);
	 }
	sort(b+1,b+n+1);
	for(int i = 1;i<= n;i++)
	{
		scanf("%d",&a[i].d);
		a[i].pos = i;
	}
	sort(a+1,a+n+1,cmp1);
	for(int i = 1;i<= n;i++)
	{
		a[i].u = b[i];
	}
	sort(a+1,a+n+1,cmp2);
	for(int i = 1;i<= n;i++)
		if(i == n)
			printf("%d\n",a[i].u);
		else
			printf("%d ",a[i].u);
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <functional>
#include <set>
#include <queue>
#include <string>
#include <map>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;
const ll MAXN = 2e5 + 10;

pair<int, int> b[MAXN];
int a[MAXN], ans[MAXN];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int m;
	cin >> m;
	for (int i = 0; i < m; ++i) {
		cin >> a[i];
	}

	for (int i = 0; i < m; ++i) {
		cin >> b[i].first;
		b[i].second = i;
	}

	sort(a, a + m);
	sort(b, b + m, greater<pair<int, int>>());

	for (int i = 0; i < m; ++i) {
		ans[b[i].second] = a[i];
	}

	for (int i = 0; i < m; ++i) {
		cout << ans[i] << ' ';
	}

	return 0;
}


#include <stdio.h>
#include <algorithm>
using namespace std;

int n;

struct ABC {
	int x, y, idx;
} P[200002];

int x[200002], y[200002];

int main() {

	scanf("%d", &n);

	for (int i = 0; i < n; i++) scanf("%d", &x[i]);
	for (int i = 0; i < n; i++) scanf("%d", &P[i].y), P[i].idx = i;

	sort(x, x + n);
	sort(P, P + n, [](const ABC &i, const ABC &j) { return i.y > j.y; });

	for (int i = 0; i < n; i++) P[i].x = x[i];

	sort(P, P + n, [](const ABC &i, const ABC &j) { return i.idx < j.idx; });

	for (int i = 0; i < n; i++) printf("%d ", P[i].x);

	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string.h>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>

using namespace std;
typedef pair<int,int> ii;
typedef long long LL;
#define MAXN 200005

int a[MAXN],b[MAXN];
priority_queue<int>que;
priority_queue<ii,vector<ii>,greater<ii> >pq;

int aa[MAXN];

int main()
{
    int m;
    cin>>m;
    for(int i=1;i<=m;i++)
    {
        cin>>a[i];
        que.push(a[i]);
    }
    for(int i=1;i<=m;i++)
    {
        cin>>b[i];
        pq.push(make_pair(b[i],i));
    }

    while(!pq.empty())
    {
        int v=pq.top().first;
        int u=pq.top().second;
        pq.pop();
        int num=que.top();
        que.pop();
        aa[u]=num;
    }
    cout<<aa[1];
    for(int i=2;i<=m;i++)
    cout<<" "<<aa[i];
    cout<<endl;

   // system("PAUSE");
    return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;

typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

#define pb push_back
#define mp make_pair

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

template<typename T> istream & operator >> (istream &in, vector<T> &vec)
{
	for(int i=0; i<vec.size();++i)
		in >> vec[i];
	return in;
}
template<typename T> ostream & operator << (ostream &out, const vector<T> &vec)
{
	for(int i=0; i<vec.size();++i)
		out << vec[i] << " ";
	return out;
}

void ans(int v=-1e9)
{
	if(v==-1e9)
		cout<<"YES"<<endl;
	else
		cout<<v<<endl;

	exit(0);
}

void err(bool check=0)
{
	if(!check)
		cout<<"NO"<<endl;
	else
		cout<<-1<<endl;
	exit(0);
}

vector<int> x,y;

bool cmp1(int a,int b)
{
	return x[a]>x[b];
}

bool cmp2(int a,int b)
{
	return y[a]<y[b];
}

void solve()
{
	ll a;
	cin>>a;

	x.resize(a);

	y.resize(a);

	for(int i=0;i<a;++i)
	{
		scanf("%d",&x[i]);
	}

	for(int i=0;i<a;++i)
	{
		scanf("%d",&y[i]);
	}

	vector<int> num1(a);
	vector<int> num2(a);

	for(int i=0;i<a;++i)
	{
		num1[i]=i;
		num2[i]=i;
	}

	sort(all(num1),cmp1);
	sort(all(num2),cmp2);

	vector<int> res(a);

	for(int i=0;i<a;++i)
	{
		res[num2[i]]=x[num1[i]];
	}

	cout<<res<<endl;
}

#define name "kitchen"
int main(int argv, char* argc[])
{
	ios::sync_with_stdio(false);

	//freopen(name ".in", "r", stdin); freopen(name ".out", "w", stdout);

	cout.setf(ios::fixed);
	cout.precision(12);

	{
		solve();
	}

	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<vector>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
vector<int>a[100005];
queue<int>p;
int ji[100005],d[100005],ma=0;
void dfs(int p,int k)
{
    ji[p]++;
    d[p]=k;
    if(k>ma)ma=k;
    for(int i=0;i<a[p].size();i++){
        if(ji[a[p][i]])continue;
        dfs(a[p][i],k+1);
    }
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        a[x].push_back(y);
        a[y].push_back(x);
    }
    dfs(1,0);
    int v,mm=0;
    for(int i=1;i<=n;i++){
        if(d[i]>mm)mm=d[i],v=i;
    }
    memset(ji,0,sizeof(ji));
    dfs(v,0);
    printf("%d\n",ma);
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
vector<vector <int> > adjlist(100001);

pair<int, int> diameter(int i, int par =-1){
  int diam =0;
  int mxHeight[3] = {-1, -1 ,-1};

  for (int j = 0 ; j < adjlist[i].size(); j++)
    if(adjlist[i][j] != par)
  {
      pair<int ,int > p = diameter(adjlist[i][j],i);
      diam = max(diam, p.first);
      mxHeight[0] = p.second + 1;
      sort(mxHeight, mxHeight + 3);

  }
  for (int j = 0 ; j < 3; j++)
    if(mxHeight[j] == -1)
        mxHeight[j] = 0;
  diam = max(diam, mxHeight[1] + mxHeight[2]);
  return make_pair(diam, mxHeight[2]);
}

int main()
{
    int n,m;
    cin >> n>>m;
    int x,y;
    for (int i = 1 ;i <= m ; i++)
    {
       cin >>x>>y;
       adjlist[x].push_back(y);
       adjlist[y].push_back(x);
    }
     cout <<diameter(1).first<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
vector<vector <int> > adjlist(1001);

pair<int, int> diameter(int i, int par =-1){
  int diam =0;
  int mxHeight[3] = {-1, -1 ,-1};

  for (int j = 0 ; j < adjlist[i].size(); j++)
    if(adjlist[i][j] != par)
  {
      pair<int ,int > p = diameter(adjlist[i][j],i);
      diam = max(diam, p.first);
      mxHeight[0] = p.second + 1;
      sort(mxHeight, mxHeight + 3);

  }
  for (int j = 0 ; j < 3; j++)
    if(mxHeight[j] == -1)
        mxHeight[j] = 0;
  diam = max(diam, mxHeight[1] + mxHeight[2]);
  return make_pair(diam, mxHeight[2]);
}

int main()
{
    int n,m;
    cin >> n>>m;
    int x,y;
    for (int i = 1 ;i <= m ; i++)
    {
       cin >>x>>y;
       adjlist[x].push_back(y);
       adjlist[y].push_back(x);
    }
     cout <<diameter(1).first<<endl;
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

vector<vector<int> > a(100000);
vector<bool> used(100000, false);
vector<bool> h(100000);
vector<int> hmax(100000);//����������� ���-�� �������, �� ��������� ���������
int ans = -1e9;

void dfs(int v)
{
    used[v] = true;
    for(int i = 0; i < a[v].size(); i++)
        if(!used[a[v][i]])
            dfs(a[v][i]);

    if(a[v].size() == 0)
    {
        hmax[v] = 0;
        ans = max(ans, 1);
    }
    else if(a[v].size() == 1)
    {
        hmax[v] = hmax[a[v][0]] + 1;
        ans = max(ans, hmax[v]);
    }
    else
    {
        int maxmax = -1e9;
        int maxx = -1e9;
        for(int i = 0; i < a[v].size(); i++)
            if(hmax[a[v][i]] >= maxmax)
            {
                maxx = maxmax;
                maxmax = hmax[a[v][i]];
            }
            else if(hmax[a[v][i]] >= maxx)
                maxx = hmax[a[v][i]];

        hmax[v] = maxmax + 1;
        ans = max(ans, maxmax + maxx + 1);
    }
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int> > ribs(m);
    for(int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        a[x - 1].push_back(y - 1);
        a[y - 1].push_back(x - 1);
    }
    dfs(0);
    /*for(int i = 0; i < n; i++)
        cout << hmax[i] << " ";
    cout << endl;*/
    cout << ans - 1;
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

vector<vector<int> > a(2501);
vector<bool> used(2501, false);
vector<bool> h(2501);
vector<int> hmax(2501);//����������� ���-�� �������, �� ��������� ���������
int ans = -1e9;

void dfs(int v)
{
    used[v] = true;
    for(int i = 0; i < a[v].size(); i++)
        if(!used[a[v][i]])
            dfs(a[v][i]);

    if(a[v].size() == 0)
    {
        hmax[v] = 0;
        ans = max(ans, 1);
    }
    else if(a[v].size() == 1)
    {
        hmax[v] = hmax[a[v][0]] + 1;
        ans = max(ans, hmax[v]);
    }
    else
    {
        int maxmax = -1e9;
        int maxx = -1e9;
        for(int i = 0; i < a[v].size(); i++)
            if(hmax[a[v][i]] >= maxmax)
            {
                maxx = maxmax;
                maxmax = hmax[a[v][i]];
            }
            else if(hmax[a[v][i]] >= maxx)
                maxx = hmax[a[v][i]];

        hmax[v] = maxmax + 1;
        ans = max(ans, maxmax + maxx + 1);
    }
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int> > ribs(m);
    for(int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        a[x - 1].push_back(y - 1);
        a[y - 1].push_back(x - 1);
    }
    dfs(0);
    /*for(int i = 0; i < n; i++)
        cout << hmax[i] << " ";
    cout << endl;*/
    cout << ans - 1;
    return 0;
}


//my magic will tear you apart!
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cstdlib>
#include <set>
using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
typedef long long ll;
const int N = 100100;
int n,m, co[N], dep[N], dia[N];
set<int> s;
vector<int> v[N], cur[N];

int depth(int nd, int fa) {
  if(dep[nd] != -1) {
    return dep[nd];
  }
  int most = 0;
  for(int i = 0; i < v[nd].size(); i++) {
    if(v[nd][i] == fa) continue;
    most = max(most, depth(v[nd][i], nd));
  }
  dep[nd] = most + 1;
  return dep[nd];
}
int diam(int nd, int fa) {
  if(dia[nd] != -1) {
    return dia[nd];
  }
  int most = 0;
  for(int i = 0; i < v[nd].size(); i++) {
    if(v[nd][i] == fa) continue;
    most = max(most, diam(v[nd][i], nd));
  }

  for(int i = 0; i < v[nd].size(); i++) {
    if(v[nd][i] == fa) continue;
    cur[nd].pb(dep[v[nd][i]]);
  }

  if(cur[nd].size() <= 1) {
    dia[nd] = max(most, dep[nd]);
    return dia[nd];
  }
  sort(cur[nd].begin(), cur[nd].end());
  dia[nd] = max(most, cur[nd][cur[nd].size() - 1] + cur[nd][cur[nd].size() - 2] + 2);
  return dia[nd];
}
int main() {
  if(fopen("C.in","r")) freopen("C.in","r",stdin);
  cin >> n >> m;
  for(int x,y,i = 0; i < m; i++) {
    scanf("%d %d",&x, &y);
    v[x].pb(y);
    v[y].pb(x);
  }
  memset(dia, -1, sizeof(dia));
  memset(dep, -1, sizeof(dep));
  depth(1,0);
  for(int i = 1; i <= n; i++) {
    dep[i]--;
  }
  diam(1,0);
  cout << dia[1] << endl;
  return 0;
}


//my magic will tear you apart!
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cstdlib>
#include <set>
using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
typedef long long ll;
const int N = 1010;
int n,m, co[N], dep[N], dia[N];
set<int> s;
vector<int> v[N];

int depth(int nd, int fa) {
  if(dep[nd] != -1) {
    return dep[nd];
  }
  int most = 0;
  for(int i = 0; i < v[nd].size(); i++) {
    if(v[nd][i] == fa) continue;
    most = max(most, depth(v[nd][i], nd));
  }
  dep[nd] = most + 1;
  return dep[nd];
}
int diam(int nd, int fa) {
  if(dia[nd] != -1) {
    return dia[nd];
  }
  int most = 0;
  for(int i = 0; i < v[nd].size(); i++) {
    if(v[nd][i] == fa) continue;
    most = max(most, diam(v[nd][i], nd));
  }

  vector<int> cur;
  for(int i = 0; i < v[nd].size(); i++) {
    if(v[nd][i] == fa) continue;
    cur.pb(dep[v[nd][i]]);
  }

  if(cur.size() <= 1) {
    dia[nd] = max(most, dep[nd]);
    return dia[nd];
  }
  sort(cur.begin(), cur.end());
  dia[nd] = max(most, cur[cur.size() - 1] + cur[cur.size() - 2] + 2);
  return dia[nd];
}
int main() {
  if(fopen("C.in","r")) freopen("C.in","r",stdin);
  cin >> n >> m;
  for(int x,y,i = 0; i < m; i++) {
    scanf("%d %d",&x, &y);
    v[x].pb(y);
    v[y].pb(x);
  }
  memset(dia, -1, sizeof(dia));
  memset(dep, -1, sizeof(dep));
  depth(1,0);
  for(int i = 1; i <= n; i++) {
    dep[i]--;
  }
  diam(1,0);
  cout << dia[1] << endl;
  return 0;
}


//my magic will tear you apart!
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cstdlib>
#include <set>
using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
typedef long long ll;
const int N = 1010;
int n,m, co[N], dep[N], dia[N];
set<int> s;
vector<int> v[N], cur[N];

int depth(int nd, int fa) {
  if(dep[nd] != -1) {
    return dep[nd];
  }
  int most = 0;
  for(int i = 0; i < v[nd].size(); i++) {
    if(v[nd][i] == fa) continue;
    most = max(most, depth(v[nd][i], nd));
  }
  dep[nd] = most + 1;
  return dep[nd];
}
int diam(int nd, int fa) {
  if(dia[nd] != -1) {
    return dia[nd];
  }
  int most = 0;
  for(int i = 0; i < v[nd].size(); i++) {
    if(v[nd][i] == fa) continue;
    most = max(most, diam(v[nd][i], nd));
  }

  for(int i = 0; i < v[nd].size(); i++) {
    if(v[nd][i] == fa) continue;
    cur[nd].pb(dep[v[nd][i]]);
  }

  if(cur[nd].size() <= 1) {
    dia[nd] = max(most, dep[nd]);
    return dia[nd];
  }
  sort(cur[nd].begin(), cur[nd].end());
  dia[nd] = max(most, cur[nd][cur[nd].size() - 1] + cur[nd][cur[nd].size() - 2] + 2);
  return dia[nd];
}
int main() {
  if(fopen("C.in","r")) freopen("C.in","r",stdin);
  cin >> n >> m;
  for(int x,y,i = 0; i < m; i++) {
    scanf("%d %d",&x, &y);
    v[x].pb(y);
    v[y].pb(x);
  }
  memset(dia, -1, sizeof(dia));
  memset(dep, -1, sizeof(dep));
  depth(1,0);
  for(int i = 1; i <= n; i++) {
    dep[i]--;
  }
  diam(1,0);
  cout << dia[1] << endl;
  return 0;
}


#include<iostream>
#include<conio.h>
#include<vector>
#include<queue>
#include<bits/stdc++.h>
#include<conio.h>
#include<cmath>
#include<string>
#include<stdio.h>
#include<algorithm>
#define ff first
#define ss second
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
typedef float fl;
typedef pair<int, int> pii;
typedef vector <int> vint;
typedef vector < pair <int,int> > pvint;
typedef vector < vector < pair<int, pair <int ,fl> > > > fvint;
typedef vector <bool> bvint;
typedef vector <vint> vvint;
const int inf=1000*1000*1000;
int n,m;vvint c;
int f(int v){
	vint d(n+1, inf); d[v]=0;bvint used(n+1,false);used[v]=true;queue <int> q;q.push(v);
	while(!q.empty()){
		int v=q.front();q.pop();used[v]=true;
		for(int i=0;i<c[v].size();i++){
			if(!used[c[v][i]] && d[c[v][i]]>d[v]+1){
				q.push(c[v][i]);
				d[c[v][i]]=d[v]+1;
			}
		}
	}
	int mx=0;
	for(int i=1;i<=n;i++)
	mx=max(d[i],mx);
	return mx;
}
int main(){
	cin>>n>>m;c.resize(n+1);
	for(int i=1;i<=m;i++){
		int a,b;cin>>a>>b;
		c[a].pb(b);c[b].pb(a);
	}
	int mx=0;
	for(int i=1;i<=n;i++){
		int t=f(i); mx=max(mx,t);
	}
	cout<<mx;
	return 0;
}


#include<iostream>
#include<conio.h>
#include<vector>
#include<queue>
#include<bits/stdc++.h>
#include<conio.h>
#include<cmath>
#include<string>
#include<stdio.h>
#include<algorithm>
#define ff first
#define ss second
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
typedef float fl;
typedef pair<int, int> pii;
typedef vector <int> vint;
typedef vector < pair <int,int> > pvint;
typedef vector <bool> bvint;
typedef vector <vint> vvint;
const int inf=1000*1000*1000+9;
int n,m;vvint c;vint d;bvint used;
void dfs(int v){
	used[v]=true;
	for(int i=0;i<c[v].size();i++){
		if(!used[c[v][i]] && d[c[v][i]]>d[v]+1){
			d[c[v][i]]=d[v]+1;
			dfs(c[v][i]);
		}
	}
}
int main()
{
	cin>>n>>m;c.resize(n+1); d.resize(n+1,inf);used.resize(n+1,false);
	for(int i=1;i<=m;i++){
		int x,y;cin>>x>>y;c[x].pb(y);c[y].pb(x);
	}int v,mx=0;
	for(int i=1;i<=n;i++){
		if(c[i].size()>0){d[i]=0;
			dfs(i);break;
		}
	}
	for(int i=1;i<=n;i++){
		if(d[i]>mx) mx=d[i],v=i;
	}
	d.clear();d.resize(n+1,inf);
	used.clear();used.resize(n+1,false);d[v]=0;
	dfs(v);mx=0;
	for(int i=1;i<=n;i++) mx=d[i]>mx?d[i]:mx;cout<<mx;
	return 0;
}


#include<iostream>
#include<conio.h>
#include<vector>
#include<queue>
#include<bits/stdc++.h>
#include<conio.h>
#include<cmath>
#include<string>
#include<stdio.h>
#include<algorithm>
#define ff first
#define ss second
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
typedef float fl;
typedef pair<int, int> pii;
typedef vector <int> vint;
typedef vector < pair <int,int> > pvint;
typedef vector < vector < pair<int, pair <int ,fl> > > > fvint;
typedef vector <bool> bvint;
typedef vector <vint> vvint;
const int inf=1000*1000*1000;
int n,m;vvint c;
int f(int v){
	vint d(n+1, inf); d[v]=0;bvint used(n+1,false);used[v]=true;queue <int> q;q.push(v);
	while(!q.empty()){
		int v=q.front();q.pop();used[v]=true;
		for(int i=0;i<c[v].size();i++){
			if(!used[c[v][i]] && d[c[v][i]]>d[v]+1){
				q.push(c[v][i]);
				d[c[v][i]]=d[v]+1;
			}
		}
	}
	int mx=0;
	for(int i=1;i<=n;i++)
	mx=max(d[i],mx);
	return mx;
}
int main(){
	cin>>n>>m;c.resize(n+1);
	for(int i=1;i<=m;i++){
		int a,b;cin>>a>>b;
		c[a].pb(b);c[b].pb(a);
	}
	int mx;
	for(int i=1;i<=n;i++){
		if(c[i].size()==1) {cout<<f(i);exit(0);}
	}
	return 0;
}


#include<iostream>
#include<conio.h>
#include<vector>
#include<queue>
#include<bits/stdc++.h>
#include<conio.h>
#include<cmath>
#include<string>
#include<stdio.h>
#include<algorithm>
#define ff first
#define ss second
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
typedef float fl;
typedef pair<int, int> pii;
typedef vector <int> vint;
typedef vector < pair <int,int> > pvint;
typedef vector < vector < pair<int, pair <int ,fl> > > > fvint;
typedef vector <bool> bvint;
typedef vector <vint> vvint;
const int inf=1000*1000*1000;
int t,n,m,sum,sum1;vvint c;
int dfs(int k){
	vector<bool>used(n+1,false);
	vector<int>min_e(n+1, inf),sel_e(n+1,-1); min_e[k]=0;int mx,nomer;
	for (int i=1; i<=n; i++){
		int v = -1;
		for(int j=1; j<=n; j++)
		if (!used[j]&&(v==-1||min_e[j]<min_e[v]))v=j;
		used[v]=true;
		for (int i=0; i<c[v].size(); i++){
			if(min_e[ c[v][i] ]>min_e[v]+1){
				min_e[ c[v][i] ]=min_e[v]+1;
				sel_e[ c[v][i] ]=v;int t=mx;
				mx=max(mx,min_e[c[v][i]]);if(t!=mx) nomer=c[v][i];
			}
		}
	}
	if(t) sum=mx;else sum1=mx;
	return nomer;
}
int main(){
	cin>>n>>m;c.resize(n+1);//uses.resize(n+1,false);d.resize(n+1,inf);
	for(int i=1;i<=m;i++){
		int x,y;cin>>x>>y;
		c[x].pb(y);c[y].pb(x);
	}
	t=1;
	int j=dfs(1);
	t=0;dfs(j);cout<<sum1;
	return 0;
}


#include<iostream>
#include<conio.h>
#include<vector>
#include<queue>
#include<bits/stdc++.h>
#include<conio.h>
#include<cmath>
#include<string>
#include<stdio.h>
#include<algorithm>
#define ff first
#define ss second
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
typedef float fl;
typedef pair<int, int> pii;
typedef vector <int> vint;
typedef vector < pair <int,int> > pvint;
typedef vector < vector < pair<int, pair <int ,fl> > > > fvint;
typedef vector <bool> bvint;
typedef vector <vint> vvint;
const int inf=1000*1000*1000;
int t,n,m,sum,sum1;vvint c;
int dfs(int k){
	vector<bool>used(n+1,false);
	vector<int>min_e(n+1, inf),sel_e(n+1,-1); min_e[k]=0;int mx,nomer;
	for (int i=1; i<=n; i++){
		int v = -1;
		for(int j=1; j<=n; j++)
		if (!used[j]&&(v==-1||min_e[j]<min_e[v]))v=j;
		used[v]=true;
		for (int i=0; i<c[v].size(); i++){
			if(min_e[ c[v][i] ]>min_e[v]+1){
				min_e[ c[v][i] ]=min_e[v]+1;
				sel_e[ c[v][i] ]=v;int t=mx;
				mx=max(mx,min_e[c[v][i]]);if(t!=mx) nomer=c[v][i];
			}
		}
	}
	if(t==1) sum=mx;//else sum1=mx;
	return nomer;
}
int main(){
	cin>>n>>m;c.resize(n+1);//uses.resize(n+1,false);d.resize(n+1,inf);
	for(int i=1;i<=m;i++){
		int x,y;cin>>x>>y;
		c[x].pb(y);c[y].pb(x);
	}
	int j=dfs(1);t=1;
	dfs(j);cout<<sum;
	return 0;
}


#include<iostream>
#include<conio.h>
#include<vector>
#include<queue>
#include<bits/stdc++.h>
#include<conio.h>
#include<cmath>
#include<string>
#include<stdio.h>
#include<algorithm>
#define ff first
#define ss second
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
typedef float fl;
typedef pair<int, int> pii;
typedef vector <int> vint;
typedef vector < pair <int,int> > pvint;
typedef vector < vector < pair<int, pair <int ,fl> > > > fvint;
typedef vector <bool> bvint;
typedef vector <vint> vvint;
const int inf=1000*1000*1000;
int n,m;vvint c;
int main(){
	cin>>n>>m;c.resize(n+1);
	for(int i=1;i<=m;i++){
		int a,b;cin>>a>>b;
		c[a].pb(b);c[b].pb(a);
	}
	int mx=0;
	for(int k=1;k<=n;k++){
		vector<bool>used(n+1,false);
		vector<int>min_e(n+1, inf),sel_e(n+1,-1); min_e[k]=0;
		for (int i=1; i<=n; i++){
			int v = -1;
			for(int j=1; j<=n; j++)
			if (!used[j]&&(v==-1||min_e[j]<min_e[v]))v=j;
			used[v]=true;
			for (int i=0; i<c[v].size(); i++){
				if(min_e[ c[v][i] ]>min_e[v]+1){
					min_e[ c[v][i] ]=min_e[v]+1;
					sel_e[ c[v][i] ]=v;
					mx=max(mx,min_e[c[v][i]]);
				}
			}
		}
	}
	cout<<mx;
	return 0;
}


//Anik_Modak
#include<bits/stdc++.h>
#define MX 100005
#define mem(x,y) memset(x,y,sizeof(x));
#define clear(x) for(int i = 0; i < MX; i++) x[i].clear();
#define set(x,y) for(int i = 0; i < MX; i++) x[i]=y;
#define pii pair<int,int>
#define ll long long
#define pb(x) push_back(x)
using namespace std;

vector <int> adj[MX];
int level[MX];
bool vis[MX];

int bfs(int source)
{
    queue <int> vc;
    int a,b,mx=0;
    level[source]=0;
    vis[source]=1;

    vc.push(source);
    while(!vc.empty())
    {
        a=vc.front();
        vc.pop();
        for(int i=0; i<adj[a].size(); i++)
        {
            b=adj[a][i];
            if(vis[b]==0)
            {
                level[b]=level[a]+1;
                mx=max(level[b],mx);
                vis[b]=1;
                vc.push(b);
            }
        }
    }
    return mx;
}

int main()
{
    int n,m,s;
    cin>>n>>m;

    clear(adj);
    mem(level,0);

    for(int i=1; i<=m; i++)
    {
        int a,b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    int ans=0;

    for(int i=1; i<=n; i++)
    {
        mem(vis,0);
        ans=max(bfs(i),ans);
    }
    cout<<ans<<endl;
    return 0;
}


//Anik_Modak
#include<bits/stdc++.h>
#define MX 100005
#define mem(x,y) memset(x,y,sizeof(x));
#define clear(x) for(int i = 0; i < MX; i++) x[i].clear();
#define set(x,y) for(int i = 0; i < MX; i++) x[i]=y;
#define pii pair<int,int>
#define ll long long
#define pb(x) push_back(x)
using namespace std;

vector <int> adj[MX];
int level[MX];
bool vis[MX];

int bfs_node(int source)
{
    mem(vis,0);
    queue <int> vc;
    int a,b,mx=0,id=0;
    level[source]=0;
    vis[source]=1;

    vc.push(source);
    while(!vc.empty())
    {
        a=vc.front();
        vc.pop();
        for(int i=0; i<adj[a].size(); i++)
        {
            b=adj[a][i];
            if(vis[b]==0)
            {
                level[b]=level[a]+1;
                vis[b]=1;
                vc.push(b);
                if(mx<=level[b])
                {
                    mx=level[b];
                    id=b;
                }
            }
        }
    }
    return id;
}

int bfs(int source)
{
    mem(vis,0);
    queue <int> vc;
    int a,b,mx=0;
    level[source]=0;
    vis[source]=1;

    vc.push(source);
    while(!vc.empty())
    {
        a=vc.front();
        vc.pop();
        for(int i=0; i<adj[a].size(); i++)
        {
            b=adj[a][i];
            if(vis[b]==0)
            {
                level[b]=level[a]+1;
                mx=max(level[b],mx);
                vis[b]=1;
                vc.push(b);
            }
        }
    }
    return mx;
}

int main()
{
    int n,m,s;
    cin>>n>>m;

    clear(adj);
    mem(level,0);

    for(int i=1; i<=m; i++)
    {
        int a,b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    int ans=0;
    ans=bfs(bfs_node(1));
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

const int N = 100 * 1000 + 10;
bool mark[N];
int d[N], n;
vector <int> graph[N];

void dfs(int v)
{
	mark[v] = true;
	for (int i = 0; i < (int) graph[v].size(); i++)
	{
		int u = graph[v][i];
		if (!mark[u])
		{
			d[u] = d[v] + 1;
			dfs(u);
		}
	}
}

int fur(int v)
{
	for (int i = 0; i < n; i++)
	{
		mark[i] = false;
		d[i] = 0;
	}
	dfs(v);
	int ind = v;
	for (int i = 0; i < n; i++)
		if (d[ind] < d[i])
			ind = i;
	return ind;
}

int main()
{
	int m;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	int v = fur(0);
	v = fur(v);
	cout << d[v] << endl;
	return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll fcurr=1;
ll flev=0;
vector<ll> vec[100005];
dfs(ll curr,ll par,ll level)
{
	for(ll i=0;i<vec[curr].size();i++)
	{
		if(vec[curr][i]!=par)
		{
			dfs(vec[curr][i],curr,level+1);
		}
	}
	if(flev<level)
	{
		flev=level;
		fcurr=curr;
	}
}
int main()
{
	ll n,m,i,a,b;
	cin>>n>>m;
	for(i=0;i<m;i++)
	{
		cin>>a>>b;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	dfs(1,1,0);
	flev=0;
	dfs(fcurr,fcurr,0);
	cout<<flev<<endl;
}


#include <cstdio>
#include <cstring>//如果一道题目能够化成多项式乘积的形式，那么就可以用FFT写
#include <cmath>
#include <algorithm>
#include <queue>
//#include <pair>
using namespace std;

const int max_n=100005;
const int max_e=200005;

queue< pair<int,int> > unc;

struct edge{
    int to;
    int next;
}es[max_e];
int head[max_n];
int cnt=0;
int n,m;
bool vis[max_n];
int ans;

int bfs(int s){
    for(int i=1;i<=n;i++){
        vis[i]=false;
    }
    ans=0;
    int res=s;
    unc.push(make_pair(s,0));
    while(!unc.empty()){
        int u=unc.front().first;
        int dis=unc.front().second;
        if(dis>ans){
            ans=dis;
            res=u;
        }
        unc.pop();
        vis[u]=true;
        for(int i=head[u];i!=-1;i=es[i].next){
            int v=es[i].to;
            if(!vis[v]){
                unc.push(make_pair(v,dis+1));
            }
        }
    }
    return res;
}

void add(int u,int v){
    es[cnt].to=v;
    es[cnt].next=head[u];
    head[u]=cnt++;
}

int main()
{
    int p,q;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        head[i]=-1;
    }
    for(int i=0;i<m;i++){
        scanf("%d%d",&p,&q);
        add(p,q);
        add(q,p);
    }
    int v1=bfs(1);
    bfs(v1);
    printf("%d\n",ans);
    return 0;
}


#include <cstdio>
#include <cstring>//如果一道题目能够化成多项式乘积的形式，那么就可以用FFT写
#include <cmath>
#include <algorithm>
#include <queue>
//#include <pair>
using namespace std;

const int max_n=100005;
const int max_e=100005;

queue< pair<int,int> > unc;

struct edge{
    int to;
    int next;
}es[max_e];
int head[max_n];
int cnt=0;
int n,m;
bool vis[max_n];
int ans;

int bfs(int s){
    for(int i=1;i<=n;i++){
        vis[i]=false;
    }
    ans=0;
    int res=s;
    unc.push(make_pair(s,0));
    while(!unc.empty()){
        int u=unc.front().first;
        int dis=unc.front().second;
        if(dis>ans){
            ans=dis;
            res=u;
        }
        unc.pop();
        vis[u]=true;
        for(int i=head[u];i!=-1;i=es[i].next){
            int v=es[i].to;
            if(!vis[v]){
                unc.push(make_pair(v,dis+1));
            }
        }
    }
    return res;
}

void add(int u,int v){
    es[cnt].to=v;
    es[cnt].next=head[u];
    head[u]=cnt++;
}

int main()
{
    int p,q;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        head[i]=-1;
    }
    for(int i=0;i<m;i++){
        scanf("%d%d",&p,&q);
        add(p,q);
        add(q,p);
    }
    int v1=bfs(1);
    bfs(v1);
    printf("%d\n",ans);
    return 0;
}


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

typedef long long LL;
typedef pair<int, int> II;

const int N = (int) 1e5 + 10;
const int INF = 0x3f3f3f3f;
int n, m, d[N];
vector<int> adj[N];

int BFS(int s) {
	queue<int> Q;
	for (int i = 1; i <= n; ++i) d[i] = INF;

	Q.push(s); d[s] = 0;
	while (Q.size()) {
		int u = Q.front(); Q.pop();
		for (int i = 0; i < (int) adj[u].size(); ++i) {
			int v = adj[u][i];
			if (d[v] == INF) {
				d[v] = d[u] + 1;
				Q.push(v);
			}
		}
	}
	return max_element(d + 1, d + 1 + n) - d;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n - 1; ++i) {
		int u, v; scanf("%d%d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	int s = BFS(1);
	int t = BFS(s);
	printf("%d", d[t]);
	return 0;
}


#include<map>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cstring>
#include<string>
#include<math.h>
#include<sstream>
#include<cctype>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<cstdlib>
#include<cassert>
#include<utility>
#include<complex>
#include<bitset>

using namespace std;

#define L long
#define LL long long
//#define ULL unsigned long long
//#define D double
//#define LD long double
#define f first
#define s second
//#define x first
//#define y second
//#define G getchar_unlocked
#define mp make_pair
#define pb push_back
#define INF ((1<<30)+(1<<29))
#define MOD 1000000007
inline LL max(LL a,LL b){return (a>b)?a:b;}
inline int min(int a,int b){return (a<b)?a:b;}
LL gcd(LL a,LL b){return (b)?gcd(b,a%b):a;}
inline LL ab(LL a){return (a>0)?a:-a;}
LL lcm(LL a,LL b){return (a*b)/gcd(max(a,b),min(a,b));}
LL modpow(LL n,LL k,LL mod)
{LL ans=1;while(k>0){if(k&1)ans=(ans*n)%mod;k>>=1;n=(n*n)%mod;}return ans;}
LL poww(LL n ,LL k)
{LL ans=1;while(k>0){if(k&1)ans=(ans*n);k>>=1;n=(n*n);}return ans;}
//double min(double a,double b){return (a<b)?a:b;}
//double max(double a,double b){return (a>b)?a:b;}
//double ab(double x){return (x>=0.0)?x:-x;}
int myrandom(int i){return rand()%i;}

LL ans=0;
vector<LL>V[100005];
LL Vis[100005]={};

LL dfs(LL x)
{
	LL l1,l2,i,v;
	l1=0,l2=0;
	Vis[x]=1;
	for(i=0;i<V[x].size();i++)
	{
		if(Vis[V[x][i]]==0)
		{
			v=dfs(V[x][i]);
			if(v>=l1)
			{
				l2=l1;
				l1=v;
			}
			else
			if(v>=l2)
			{
				l2=v;
			}
		}
	}
	if(l2==0)
	{
		ans=max(ans,l1);
	}
	else
	{
		ans=max(ans,l1+l2);
	}
	return l1+1;
}

int main()
{
	ios::sync_with_stdio(false);
	LL n,m,i,x,y;
	cin>>n>>m;
	for(i=0;i<m;i++)
	{
		cin>>x>>y;
		V[x].pb(y);
		V[y].pb(x);
	}
	Vis[1]=1;
	ans=max(ans,dfs(1)-1);
	cout<<ans<<endl;
	return 0;
}


#include<map>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cstring>
#include<string>
#include<math.h>
#include<sstream>
#include<cctype>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<cstdlib>
#include<cassert>
#include<utility>
#include<complex>
#include<bitset>

using namespace std;

#define L long
#define LL long long
//#define ULL unsigned long long
//#define D double
//#define LD long double
#define f first
#define s second
//#define x first
//#define y second
//#define G getchar_unlocked
#define mp make_pair
#define pb push_back
#define INF ((1<<30)+(1<<29))
#define MOD 1000000007
inline LL max(LL a,LL b){return (a>b)?a:b;}
inline int min(int a,int b){return (a<b)?a:b;}
LL gcd(LL a,LL b){return (b)?gcd(b,a%b):a;}
inline LL ab(LL a){return (a>0)?a:-a;}
LL lcm(LL a,LL b){return (a*b)/gcd(max(a,b),min(a,b));}
LL modpow(LL n,LL k,LL mod)
{LL ans=1;while(k>0){if(k&1)ans=(ans*n)%mod;k>>=1;n=(n*n)%mod;}return ans;}
LL poww(LL n ,LL k)
{LL ans=1;while(k>0){if(k&1)ans=(ans*n);k>>=1;n=(n*n);}return ans;}
//double min(double a,double b){return (a<b)?a:b;}
//double max(double a,double b){return (a>b)?a:b;}
//double ab(double x){return (x>=0.0)?x:-x;}
int myrandom(int i){return rand()%i;}

LL ans=0;
vector<LL>V[100005];
LL Vis[100005]={};

LL dfs(LL x)
{
	LL l1,l2,i,v;
	l1=l2=0;
	Vis[x]=1;
	for(i=0;i<V[x].size();i++)
	{
		if(Vis[V[x][i]]==0)
		{
			v=dfs(V[x][i]);
			if(v>=l1)
			{
				l2=l1;
				l1=v;
			}
			else
			if(v>=l2)
			{
				l2=v;
			}
		}
	}
	ans=max(ans,l1+l2-1);
	return l1+1;
}

int main()
{
	ios::sync_with_stdio(false);
	LL n,m,i,x,y;
	cin>>n>>m;
	for(i=0;i<m;i++)
	{
		cin>>x>>y;
		V[x].pb(y);
		V[y].pb(x);
	}
	Vis[1]=1;
	ans=max(ans,dfs(1)-1);
	cout<<ans<<endl;
	return 0;
}


/*
 * STL refer:
 * a.insert(a.end(), b.begin(), b.end());
 * copy(b.begin(), b.end(), back_inserter(a));
 * */
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <sstream>
#include <queue>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <ctime>
#include <cassert>

using namespace std;

#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define range(i, n) for (int i=0; i<(n); ++i)
#define range2(i, m,  n) for (int i=m; i<(n); ++i)
#define forit(it,v) for(typeof((v).begin()) it = v.begin() ; it != (v).end() ; ++it)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),a.end()

typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double eps = 1e-8;
const double pi = acos(-1.0);

//copy from dumbear(Yaxiong Liang)
int sgn(double d) {
    return d > eps ? 1 : (d < -eps ? -1 : 0);
}

double trim(double d, double l = 1.0) {
    return d > l ? l : (d < -l ? -l : d);
}

const int N = 100000 + 5;

vector<int> g[N];

PII bfs(int start, int n) {
    vector<int> vis;
    range(i, n) vis.push_back(-1);
    vis[start] = 0;
    PII ret;
    ret = mp(0, start);
    queue<int> Q;
    Q.push(start);
    while (!Q.empty()) {
        int cur = Q.front();
		Q.pop();
        range(i, g[cur].size()) {
            int nei = g[cur][i];
            if (vis[nei] != -1) continue;
            vis[nei] = vis[cur] + 1;
            if (vis[nei] > ret.first) {
                ret = mp(vis[nei], nei);
            }
            Q.push(nei);
        }
    }
    return ret;
}

int main() {
    ios :: sync_with_stdio(false);

    int n,m;
    cin >> n >> m;
    int x,y;
    range(i, n - 1) {
        cin >> x >> y;
        --x; --y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    PII ret = bfs(0, n);
    ret = bfs(ret.second, n);
    cout << ret.first << endl;
    /*
    vector<PII> vp;
    vp.pb(mp(5, 2));
    vp.pb(mp(3, 4));
    vp.pb(mp(6, 1));
    range(i, vp.size()) {
        eprintf("(%d, %d)\n", vp[i].fs, vp[i].sc);
    }
    range2(i, 3, 5) {
        eprintf("range2: %d\n", i);
    }
    forit(it, vp) {
        eprintf("(%d, %d)\n", it->fs, it->sc);
    }
    cout << "sz = " << sz(vp) << endl;
    sort(all(vp));
    forit(it, vp) {
        eprintf("(%d, %d)\n", it->fs, it->sc);
    }
    point p(4.0, 2.0);
    cout << p.tostring() << endl;
    cout << (p * 5).tostring() << endl;
    cout << (p / 2).tostring() << endl;
    cout << (p ^ point(3, 4)) << endl;
    */
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

#define p_b push_back
const int MAXN = 100 *1000 + 10;
vector <int> vec[MAXN];
int dist[MAXN];
bool mark[MAXN];

void dfs(int v, int h)
{
	dist[v] = h;
	mark[v] = true;
	for(int i = 0; i < (int)vec[v].size(); i++)
		if(!mark[vec[v][i]])
			dfs(vec[v][i], h + 1);
}
int main()
{
	int n, m;
	cin>> n >> m;

	for(int i = 0; i < m; i++)
	{
		int a, b;
		cin>> a >> b;
		a--, b--;
		vec[a].p_b(b);
		vec[b].p_b(a);
	}

	dfs(0, 0);
	int mx = 0, x;
	for(int i = 0; i < n; i++)
	{
		mark[i] = false;
		if(dist[i] >= mx)
			mx = dist[i], x = i;
	}

	dfs(x, 0);
	mx = 0;

	for(int i = 0; i < n; i++)
		mx = max(mx, dist[i]);
	cout<< mx << endl;
}


#include <iostream>
#include <vector>
using namespace std;

#define p_b push_back
const int MAXN = 1000 + 10;
vector <int> vec[MAXN];
int dist[MAXN];
bool mark[MAXN];

void dfs(int v, int h)
{
	dist[v] = h;
	mark[v] = true;
	for(int i = 0; i < (int)vec[v].size(); i++)
		if(!mark[vec[v][i]])
			dfs(vec[v][i], h + 1);
}
int main()
{
	int n, m;
	cin>> n >> m;

	for(int i = 0; i < m; i++)
	{
		int a, b;
		cin>> a >> b;
		a--, b--;
		vec[a].p_b(b);
		vec[b].p_b(a);
	}

	dfs(0, 0);
	int mx = 0, x;
	for(int i = 0; i < n; i++)
	{
		mark[i] = false;
		if(dist[i] >= mx)
			mx = dist[i], x = i;
	}

	dfs(x, 0);
	mx = 0;

	for(int i = 0; i < n; i++)
		mx = max(mx, dist[i]);
	cout<< mx << endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn = 100006;
int f[maxn], g[maxn], h[maxn], longest[maxn];
vector<int> son[maxn], w[maxn];

int dfs(int root, int pre){
    int i, j;
    int est = 0, esti=-1, er=0;
    if(f[root]!=-1) return f[root];
    if(son[root].empty()) return f[root] = 0;
    for(i=0;i<son[root].size();i++){
        if(pre!=son[root][i]){
            if(dfs(son[root][i],root)+w[root][i]>est){
                est = f[son[root][i]]+w[root][i];
                esti = i;
            }
        }
    }
    longest[root] = esti;
    for(i=0;i<son[root].size();i++){
        if(pre!=son[root][i]){
            if(f[son[root][i]]+w[root][i]>er&&i!=longest[root]){
                er = f[son[root][i]]+w[root][i];
            }
        }
    }
    g[root] = er;
    return f[root] = est;
}

void dfs1(int root, int pre){
    int i, j;
    for(i=0;i<son[root].size();i++){
        if(pre!=son[root][i]){
            if(i!=longest[root]){
                h[son[root][i]] = max(h[root],f[root])+w[root][i];
            }
            else{
                h[son[root][i]] = max(h[root],g[root])+w[root][i];
            }
            dfs1(son[root][i],root);
        }
    }
}

void Init(int n){
    int i;
    for(i=0;i<=n;i++){
        f[i] = g[i] = h[i] = longest[i] = -1;
        son[i].clear();
        w[i].clear();
    }
}
int main(){
    int i, j, k, n, m, ans;
    int x1, x2, l;
    scanf("%d%d",&n,&m);
        Init(n);
        for(i=0;i<m;i++){
            scanf("%d%d",&x1,&x2);
            l = 1;
            son[x1].push_back(x2);w[x1].push_back(l);
            son[x2].push_back(x1);w[x2].push_back(l);
        }
        for(i=1;i<=n;i++){
            if(f[i]==-1){
                f[i] = dfs(i,-1);
                h[i] = 0; dfs1(i,-1);
            }
        }
        ans = 0;
        for(i=1;i<=n;i++){
            ans = max(ans,max(f[i],h[i]));
        }
        printf("%d\n",ans);
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <numeric>
#include <vector>
using namespace std;
int n,m;
const int MAXN = 100009;
int maxx;
vector<int> ivectwo[MAXN];
bool visited[MAXN];

void dfs(int be,int num)
{
    num++;
    visited[be] = true;
    if (num > maxx)
        maxx = num;
    //if (ivectwo[be].empty())
        //return;
    for (int j = 0; j < ivectwo[be].size(); ++j)
    {
        if (!visited[ivectwo[be][j]])
            dfs(ivectwo[be][j], num);
    }
}

int main()
{
    int tmp1,tmp2;
    scanf("%d%d",&n,&m);
    for (int i = 1; i <= m; ++i)
    {
        scanf("%d%d",&tmp1,&tmp2);
        ivectwo[tmp1].push_back(tmp2);
        ivectwo[tmp2].push_back(tmp1);
    }
    maxx = 0;
    for (int i = 1; i <= n; ++i)
    {
        memset(visited,0,sizeof(visited));
        dfs(i,0);
    }
    cout << maxx-1 << endl;
    return 0;
}

/*
int root[MAXN];
const int MAXN = 10005;

bool flag;
set<int>iset;

int find_root(int x)
{
    if (root[x] != x)
        root[x] = find_root(root[x]);
    return root[x];
}

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int root1,root2,tmp1,tmp2;
    for (int i = 0; i < MAXN; ++i)
        root[i] = i;
    bool flag = false;
    int tmp;
    for (int i = 0; i < m; ++i)
    {
        scanf("%d%d",&tmp1,&tmp2);
        root1 = find_root(tmp1);
        root2 = find_root(tmp2);
        if (root1 == root2 || root1 == root[root2] || root2 == root[root1])
        {
            flag = true;
            continue;
        }
        if (root1 != root2)
            root[root2] = root1;
    }
    if (m != n-1)
    {
        cout << "no" << endl;
        return 0;
    }
    for (int i = 0; i < MAXN; ++i)
    {
        if (root[i] != i)
        {
            tmp = find_root(i);
            iset.insert(tmp);
        }
    }
    if (iset.size() > 1)
        flag = true;
    if (flag)
        cout << "no" << endl;
    else
        cout << "yes" << endl;
    return 0;
}*/


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <numeric>
#include <vector>
using namespace std;
int n,m;
const int MAXN = 10005;
int maxx;
vector<int> ivectwo[MAXN];
bool visited[MAXN];

void dfs(int be,int num)
{
    num++;
    visited[be] = true;
    if (num > maxx)
        maxx = num;
    //if (ivectwo[be].empty())
        //return;
    for (int j = 0; j < ivectwo[be].size(); ++j)
    {
        if (!visited[ivectwo[be][j]])
            dfs(ivectwo[be][j], num);
    }
}

int main()
{
    int tmp1,tmp2;
    scanf("%d%d",&n,&m);
    for (int i = 0; i < m; ++i)
    {
        scanf("%d%d",&tmp1,&tmp2);
        ivectwo[tmp1].push_back(tmp2);
        ivectwo[tmp2].push_back(tmp1);
    }
    maxx = 0;
    for (int i = 0; i < n; ++i)
    {
        memset(visited,0,sizeof(visited));
        //if (!ivectwo[i].empty())
        //{
            dfs(i,0);
        //}

    }
    cout << maxx-1 << endl;
    return 0;
}

/*
int root[MAXN];
const int MAXN = 10005;

bool flag;
set<int>iset;

int find_root(int x)
{
    if (root[x] != x)
        root[x] = find_root(root[x]);
    return root[x];
}

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int root1,root2,tmp1,tmp2;
    for (int i = 0; i < MAXN; ++i)
        root[i] = i;
    bool flag = false;
    int tmp;
    for (int i = 0; i < m; ++i)
    {
        scanf("%d%d",&tmp1,&tmp2);
        root1 = find_root(tmp1);
        root2 = find_root(tmp2);
        if (root1 == root2 || root1 == root[root2] || root2 == root[root1])
        {
            flag = true;
            continue;
        }
        if (root1 != root2)
            root[root2] = root1;
    }
    if (m != n-1)
    {
        cout << "no" << endl;
        return 0;
    }
    for (int i = 0; i < MAXN; ++i)
    {
        if (root[i] != i)
        {
            tmp = find_root(i);
            iset.insert(tmp);
        }
    }
    if (iset.size() > 1)
        flag = true;
    if (flag)
        cout << "no" << endl;
    else
        cout << "yes" << endl;
    return 0;
}*/


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <numeric>
#include <vector>
using namespace std;
int n,m;
const int MAXN = 20005;
int maxx;
vector<int> ivectwo[MAXN];
bool visited[MAXN];

void dfs(int be,int num)
{
    num++;
    visited[be] = true;
    if (num > maxx)
        maxx = num;
    //if (ivectwo[be].empty())
        //return;
    for (int j = 0; j < ivectwo[be].size(); ++j)
    {
        if (!visited[ivectwo[be][j]])
            dfs(ivectwo[be][j], num);
    }
}

int main()
{
    int tmp1,tmp2;
    scanf("%d%d",&n,&m);
    for (int i = 0; i < m; ++i)
    {
        scanf("%d%d",&tmp1,&tmp2);
        ivectwo[tmp1].push_back(tmp2);
        ivectwo[tmp2].push_back(tmp1);
    }
    maxx = 0;
    for (int i = 1; i <= n; ++i)
    {
        memset(visited,0,sizeof(visited));
        dfs(i,0);
    }
    cout << maxx-1 << endl;
    return 0;
}

/*
int root[MAXN];
const int MAXN = 10005;

bool flag;
set<int>iset;

int find_root(int x)
{
    if (root[x] != x)
        root[x] = find_root(root[x]);
    return root[x];
}

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int root1,root2,tmp1,tmp2;
    for (int i = 0; i < MAXN; ++i)
        root[i] = i;
    bool flag = false;
    int tmp;
    for (int i = 0; i < m; ++i)
    {
        scanf("%d%d",&tmp1,&tmp2);
        root1 = find_root(tmp1);
        root2 = find_root(tmp2);
        if (root1 == root2 || root1 == root[root2] || root2 == root[root1])
        {
            flag = true;
            continue;
        }
        if (root1 != root2)
            root[root2] = root1;
    }
    if (m != n-1)
    {
        cout << "no" << endl;
        return 0;
    }
    for (int i = 0; i < MAXN; ++i)
    {
        if (root[i] != i)
        {
            tmp = find_root(i);
            iset.insert(tmp);
        }
    }
    if (iset.size() > 1)
        flag = true;
    if (flag)
        cout << "no" << endl;
    else
        cout << "yes" << endl;
    return 0;
}*/


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define sll set<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ln length()
#define M 1000000007
#define endl '\n'
#define FIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
ll n,m,mark[1005],maxi,maxiV;
vll nb[1005];
void dfs(ll st, ll depth, ll p) {
    if (depth > maxi) {
        maxi = depth;
        maxiV = st;
    }
    for (int i = 0; i < nb[st].size(); i++) {
        ll to = nb[st][i];
        if (to != p) dfs(to, depth + 1, st);
    }
}

ll findLongestWay(int v) {
    maxi = -1;
    dfs(v, 0, -1);
    maxi = -1;
    dfs(maxiV, 0, -1);
    return maxi;
}

int main(){
    FIO;
    cin>>n>>m;
    rep(i,1,m){
        ll u,v;cin>>u>>v;
        nb[u].pb(v);
        nb[v].pb(u);
    }
    cout<<findLongestWay(1);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define sll set<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ln length()
#define M 1000000007
#define endl '\n'
#define FIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
ll n,m,mark[100005],maxi,maxiV;
vll nb[100005];
void dfs(ll st, ll depth, ll p) {
    if (depth > maxi) {
        maxi = depth;
        maxiV = st;
    }
    for (int i = 0; i < nb[st].size(); i++) {
        ll to = nb[st][i];
        if (to != p) dfs(to, depth + 1, st);
    }
}

ll findLongestWay(int v) {
    maxi = -1;
    dfs(v, 0, -1);
    maxi = -1;
    dfs(maxiV, 0, -1);
    return maxi;
}

int main(){
    FIO;
    cin>>n>>m;
    rep(i,1,m){
        ll u,v;cin>>u>>v;
        nb[u].pb(v);
        nb[v].pb(u);
    }
    cout<<findLongestWay(1);
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN=100005;
int level[MAXN];
bool visit[MAXN];
vector<int >adj[MAXN];
void intialise(){
	for(int i=0;i<MAXN;i++)
	level[i]=visit[i]=0;
}
void bfs(int start){
	queue<int>q;
	q.push(start);
	visit[start]=1;
	level[start]=1;
	while(!q.empty()){
		int p=q.front();
		q.pop();
		for(int i=0;i<adj[p].size();i++){
			if(visit[adj[p][i]]==false){
				visit[adj[p][i]]=true;
				level[adj[p][i]]=level[p]+1;
				q.push(adj[p][i]);
			}
		}

	}
}
int main(){
	int n,m;
	cin>>n>>m;
	int x,y;
	while(m--){
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	bfs(1);
	int max1=0;
	int j;
	//cout<<level[1]<<" "<<level[2]<<endl;
	for(int i=1;i<MAXN;i++){
		if(level[i]>max1){
          j=i;
		max1=max(max1,level[i]);
}
	}
	//cout<<j<<endl;
	intialise();
	bfs(j);
	for(int i=0;i<MAXN;i++){
		if(level[i]>max1){
          j=i;
		max1=max(max1,level[i]);
}
	}
	cout<<max1-1<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN=100005;
int level[MAXN];
bool visit[MAXN];
vector<int >adj[MAXN];
void intialise(){
	for(int i=0;i<MAXN;i++)
	level[i]=visit[i]=0;
}
void bfs(int start){
	queue<int>q;
	q.push(start);
	visit[start]=0;
	level[start]=1;
	while(!q.empty()){
		int p=q.front();
		q.pop();
		for(int i=0;i<adj[p].size();i++){
			if(visit[adj[p][i]]==false){
				visit[adj[p][i]]=true;
				level[adj[p][i]]=level[p]+1;
				q.push(adj[p][i]);
			}
		}

	}
}
int main(){
	int n,m;
	cin>>n>>m;
	int x,y;
	while(m--){
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	bfs(1);
	int max1=0;
	int j;
	for(int i=1;i<MAXN;i++){
		if(level[i]>max1){
          j=i;
		max1=max(max1,level[i]);
}
	}
//	cout<<j<<endl;
	intialise();
	bfs(j);
	for(int i=0;i<MAXN;i++){
		if(level[i]>max1){
          j=i;
		max1=max(max1,level[i]);
}
	}
	cout<<max1-1<<endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

bool vis[1005];
int n,m,maxi=0,x;
vector<int> G[1005];
void dfs(int u,int k)
{
	if(k>maxi)
	{
		maxi=k;
		x=u;
	}
    vis[u]=1;
	for(int i=0;i<G[u].size();i++)
	{
		int v=G[u][i];
		if(!vis[v])
		 dfs(v,k+1);
	}
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int x,y;
		cin>>x>>y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
	 vis[i]=0;
    dfs(x,0);
    cout<<maxi;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

bool vis[100005];
int n,m,maxi=0,x;
vector<int> G[100005];
void dfs(int u,int k)
{
	if(k>maxi)
	{
		maxi=k;
		x=u;
	}
    vis[u]=1;
	for(int i=0;i<G[u].size();i++)
	{
		int v=G[u][i];
		if(!vis[v])
		 dfs(v,k+1);
	}
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int x,y;
		cin>>x>>y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
	 vis[i]=0;
    dfs(x,0);
    cout<<maxi;
    return 0;
}


#include <cstdio>
#include <vector>
#include <queue>

std::vector<int>a[1010];
bool f[1010];
int r[1010];

int main()
{
    int n, i, m, x, y, max=1;
    scanf("%d %d", &n, &m);
    for (i=0; i<m; i++) {
        scanf ("%d %d", &x, &y);
        a[x].push_back(y);
        a[y].push_back(x);
    }
    std::queue<int>q;
    q.push(1);
    f[1]=true;
    r[1]=0;
    while ((!q.empty())) {
        x=q.front();
        q.pop();
        for (i=0; i<a[x].size(); i++) {
            if (!f[a[x][i]]) {
                q.push(a[x][i]);
                r[a[x][i]]=r[x]+1;
                f[a[x][i]]=true;
                if (r[a[x][i]]>r[max]) max=a[x][i];
            }
        }
    }
    for (i=1; i<=n; i++) {
        f[i]=false;
        r[i]=0;
    }
    q.push(max);
    f[max]=true;
    while ((!q.empty())) {
        x=q.front();
        q.pop();
        for (i=0; i<a[x].size(); i++) {
            if (!f[a[x][i]]) {
                q.push(a[x][i]);
                r[a[x][i]]=r[x]+1;
                f[a[x][i]]=true;
                if (r[a[x][i]]>r[max]) max=a[x][i];
            }
        }
    }
    printf ("%d", r[max]);
    return 0;
}


#include <cstdio>
#include <vector>
#include <queue>

std::vector<int>a[100010];
bool f[100010];
int r[100010];

int main()
{
    int n, i, m, x, y, max=1;
    scanf("%d %d", &n, &m);
    for (i=0; i<m; i++) {
        scanf ("%d %d", &x, &y);
        a[x].push_back(y);
        a[y].push_back(x);
    }
    std::queue<int>q;
    q.push(1);
    f[1]=true;
    r[1]=0;
    while ((!q.empty())) {
        x=q.front();
        q.pop();
        for (i=0; i<a[x].size(); i++) {
            if (!f[a[x][i]]) {
                q.push(a[x][i]);
                r[a[x][i]]=r[x]+1;
                f[a[x][i]]=true;
                if (r[a[x][i]]>r[max]) max=a[x][i];
            }
        }
    }
    for (i=1; i<=n; i++) {
        f[i]=false;
        r[i]=0;
    }
    q.push(max);
    f[max]=true;
    while ((!q.empty())) {
        x=q.front();
        q.pop();
        for (i=0; i<a[x].size(); i++) {
            if (!f[a[x][i]]) {
                q.push(a[x][i]);
                r[a[x][i]]=r[x]+1;
                f[a[x][i]]=true;
                if (r[a[x][i]]>r[max]) max=a[x][i];
            }
        }
    }
    printf ("%d", r[max]);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn = 100010;
int f[maxn], g[maxn], longest[maxn];
vector<int> son[maxn], w[maxn];
int dfs(int root, int pre){
    int i, j;
    int est = 0, esti=-1, er=0;
    if(f[root]!=-1) return f[root];
    if(son[root].empty()) return f[root] = 0;
    for(i=0;i<son[root].size();i++){
        if(pre!=son[root][i]){
            if(dfs(son[root][i],root)+w[root][i]>est){
                est = f[son[root][i]]+w[root][i];
                esti = i;
            }
        }
    }
    longest[root] = esti;
    for(i=0;i<son[root].size();i++){
        if(pre!=son[root][i]){
            if(f[son[root][i]]+w[root][i]>er&&i!=longest[root]){
                er = f[son[root][i]]+w[root][i];
            }
        }
    }
    g[root] = er;
    return f[root] = est;
}

void Init(int n){
    int i;
    for(i=0;i<=n;i++)
    {
        f[i] = g[i] = longest[i] = -1;
        son[i].clear();
        w[i].clear();
    }
}
int main(){
    int i, j, k, n, m, ans;
    int x1, x2, l;
    char opt;
    while(~scanf("%d%d",&n,&m)){
        Init(n);
        for(i=0;i<m;i++)
        {
            scanf("%d%d",&x1,&x2);
            son[x1].push_back(x2);w[x1].push_back(1);
            son[x2].push_back(x1);w[x2].push_back(1);
        }
        for(i=1;i<=n;i++)
        {
            if(f[i]==-1){
                f[i] = dfs(i,-1);
            }
        }
        ans = 0;
        for(i=1;i<=n;i++)
        {
            ans = max(ans,f[i]+g[i]);
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn = 40005;
int f[maxn], g[maxn], longest[maxn];
vector<int> son[maxn], w[maxn];
int dfs(int root, int pre){
    int i, j;
    int est = 0, esti=-1, er=0;
    if(f[root]!=-1) return f[root];
    if(son[root].empty()) return f[root] = 0;
    for(i=0;i<son[root].size();i++){
        if(pre!=son[root][i]){
            if(dfs(son[root][i],root)+w[root][i]>est){
                est = f[son[root][i]]+w[root][i];
                esti = i;
            }
        }
    }
    longest[root] = esti;
    for(i=0;i<son[root].size();i++){
        if(pre!=son[root][i]){
            if(f[son[root][i]]+w[root][i]>er&&i!=longest[root]){
                er = f[son[root][i]]+w[root][i];
            }
        }
    }
    g[root] = er;
    return f[root] = est;
}

void Init(int n){
    int i;
    for(i=0;i<=n;i++)
    {
        f[i] = g[i] = longest[i] = -1;
        son[i].clear();
        w[i].clear();
    }
}
int main(){
    int i, j, k, n, m, ans;
    int x1, x2, l;
    char opt;
    while(~scanf("%d%d",&n,&m)){
        Init(n);
        for(i=0;i<m;i++)
        {
            scanf("%d%d",&x1,&x2);
            son[x1].push_back(x2);w[x1].push_back(1);
            son[x2].push_back(x1);w[x2].push_back(1);
        }
        for(i=1;i<=n;i++)
        {
            if(f[i]==-1){
                f[i] = dfs(i,-1);
            }
        }
        ans = 0;
        for(i=1;i<=n;i++)
        {
            ans = max(ans,f[i]+g[i]);
        }
        printf("%d\n",ans);
    }
    return 0;
}


//C2
#include<bits/stdc++.h>
#define read_fast ios_base::sync_with_stdio( 0 ) , cin.tie( 0 )
#define pb push_back
using namespace std ;
vector < int > adj [ 10000 + 5 ] ;
int dis [ 10000 + 5 ] , timed , maxi , great [ 10000 + 5 ] ;
void dfs ( int u )
{
     dis [ u ] = ++ timed ;
     int a = 0 , b = 0 ;
     for ( int i = 0 ; i < ( int ) adj [ u ] . size () ; i ++ )
     {
          int j = adj [ u ][ i ] ;
          if ( !dis [ j ] and j != 1 ) {
               dfs ( j ) ;
               great [ u ] = max ( great [ u ] , great [ j ] ) ;
               if ( great [ j ] - dis [ u ] > a )
                    b = a , a = great [ j ] - dis [ u ] ;
               else if ( great [ j ] - dis [ u ] > b )
                    b = great [ j ] - dis [ u ] ;
          }
     }
     great [ u ] = max ( great [ u ] , dis [ u ] ) ;
     maxi = max ( maxi , a + b ) ;
     timed -- ;
}

int main()
{
     read_fast ;
     int n , m ;
     timed = -1 , maxi = 0 ;
     cin >> n >> m ;
     for ( int i = 0 ; i < m ; i ++ )
     {
          int a , b ;
          cin >> a >> b ;
          adj [ a ] . pb ( b ) , adj [ b ] . pb ( a ) ;
     }
     dfs ( 1 ) ;
     cout << maxi ;
     return 0 ;
}


//C2
#include<bits/stdc++.h>
#define read_fast ios_base::sync_with_stdio( 0 ) , cin.tie( 0 )
#define pb push_back
using namespace std ;
vector < int > adj [ 100000 + 5 ] ;
int dis [ 100000 + 5 ] , timed , maxi , great [ 100000 + 5 ] ;
void dfs ( int u )
{
     dis [ u ] = ++ timed ;
     int a = 0 , b = 0 ;
     for ( int i = 0 ; i < ( int ) adj [ u ] . size () ; i ++ )
     {
          int j = adj [ u ][ i ] ;
          if ( !dis [ j ] and j != 1 ) {
               dfs ( j ) ;
               great [ u ] = max ( great [ u ] , great [ j ] ) ;
               if ( great [ j ] - dis [ u ] > a )
                    b = a , a = great [ j ] - dis [ u ] ;
               else if ( great [ j ] - dis [ u ] > b )
                    b = great [ j ] - dis [ u ] ;
          }
     }
     great [ u ] = max ( great [ u ] , dis [ u ] ) ;
     maxi = max ( maxi , a + b ) ;
     timed -- ;
}

int main()
{
     read_fast ;
     int n , m ;
     timed = -1 , maxi = 0 ;
     cin >> n >> m ;
     for ( int i = 0 ; i < m ; i ++ )
     {
          int a , b ;
          cin >> a >> b ;
          adj [ a ] . pb ( b ) , adj [ b ] . pb ( a ) ;
     }
     dfs ( 1 ) ;
     cout << maxi ;
     return 0 ;
}


//C2
#include<bits/stdc++.h>
#define read_fast ios_base::sync_with_stdio( 0 ) , cin.tie( 0 )
#define mp make_pair
#define ll long long int
#define pb push_back
using namespace std ;
typedef pair < int , int > ii ;
vector < int > adj [ 10000 + 5 ] ;
map < ii , int > dis ;
int main()
{
     read_fast ;
     int n , m ;
     cin >>  n >> m ;
     for ( int i = 0 ; i < m ; i ++ )
     {
          int a , b ;
          cin >> a >> b ;
          dis [ mp ( a , b ) ] = dis [ mp ( b , a ) ] = 1 ;
     }
     int ans = 0 ;
     for ( int k = 1 ; k <= n ; k ++ )
          for ( int i = 1 ; i <= n ; i ++ )
               for ( int j = 1 ; j <= n ; j ++ ) {
                    if ( i == j ) continue ;
                    if ( ! dis [ mp ( i , j ) ] ) dis [ mp ( i , j ) ] = 1000 * 1000 * 1000 ;
                    dis [ mp ( i , j ) ] = min ( dis [ mp ( i , j ) ] , dis [ mp ( i , k ) ] + dis [ mp (  k , j ) ] ) ;
               }
     for ( int i = 1 ; i <= n ; i ++ )
          for ( int j = 1 ; j <= n ; j ++ )  ans = max ( ans , dis [ mp ( i , j ) ] ) ;
     cout << ans ;
     return 0 ;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<vector<int> > adj(100001);// Graph Data
int t;
int mx=-1;
vector<bool> vis(100001,false);
int dfs(int x,int m)
{
	vis[x]=true;
	int m1=0,m2=0;
	for(int i=0;i<adj[x].size();i++)
		if(!vis[adj[x][i]])
		{
			int n=dfs(adj[x][i],m+1);
			if(n>m1) m2=m1  , m1=n;
			else if(n>m2) m2=n;
		}
	if(m1==0 && m2==0 )return m;
	if(m1+m2-2*m >mx) mx=m1+m2-2*m;
	vis[x]=false;
	return m1;
}

int main()
{
    int m ;
	cin>>t >> m ;
	t--;
	while(t--)
	{
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	dfs(1,0);
	cout<<mx<<endl;

}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<vector<int> > adj(10001);// Graph Data
int t;
int mx=-1;
vector<bool> vis(10001,false);
int dfs(int x,int m)
{
	vis[x]=true;
	int m1=0,m2=0;
	for(int i=0;i<adj[x].size();i++)
		if(!vis[adj[x][i]])
		{
			int n=dfs(adj[x][i],m+1);
			if(n>m1) m2=m1  , m1=n;
			else if(n>m2) m2=n;
		}
	if(m1==0 && m2==0 )return m;
	if(m1+m2-2*m >mx) mx=m1+m2-2*m;
	vis[x]=false;
	return m1;
}

int main()
{
    int m ;
	cin>>t >> m ;
	t--;
	while(t--)
	{
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	dfs(1,0);
	cout<<mx<<endl;

}


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

#define read() freopen("input.txt","r",stdin)
#define INF ((1<<31)-1)
#define EPS (1e-9)
#define PI (2*acos(0.0))
#define ll long long
#define ull unsigned ll
#define SIZE ((ll)1e8)+10
#define testcase ll T;cin>>T;for(int t=1;t<=T;t++)
#define printcase() cout<<"Case "<<t<<":\n"
#define pb push_back
#define PAR_SIZE 30010
#define BFS_GRID 1010
#define NL() cout << endl
#define FOR(itt,n) for(int itt=0;itt<n;++itt)
#define FOR1(itt,n) for(int itt=1;itt<=n;++itt)

int c=1, f;
int ar[10000000];
struct edges{
    int n1, n2, cost;
    edges(int a, int b, int c){
        n1=a;
        n2=b;
        cost=c;
    }
};

int par[ 10010];
void makeSet(int n){
    par[n]=n;
}
int Find(int r){
    if(par[r]==r)return r;
    par[r]=Find(par[r]);
    return par[r];
}
void Union(int a, int b){
    if(Find(a)==Find(b)){
        //cout << "Same Set" << endl;
        return;
    }
    if(Find(a)!=Find(f))swap(a,b);
    par[Find(a)]=Find(b);
    if(ar[a]==2)c++;
    //cout << "Union Successful" << endl;
}
vector <edges> v;

bool cmp(edges a, edges b){
    return (a.cost < b.cost);
}

int main()
{
    #ifdef pinanzo
        read();
        //freopen("output.txt","w",stdout);
    #endif // pinanzo
    //ios_base::sync_with_stdio(0);
    //cin.tie(NULL);
    //cout.tie(NULL);

    int n, m;
    scanf("%d %d", &n, &m);

    FOR1(i,n)makeSet(i);
    bool flag = true;

    FOR(i,m){
        int a, b;

        scanf("%d %d", &a, &b);
        if(flag){
            flag = false;
            f=a;
        }
        ar[a]++;
        ar[b]++;
        Union(a,b);
    }
    cout << c << endl;

    return 0;
}


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

#define read() freopen("input.txt","r",stdin)
#define INF ((1<<31)-1)
#define EPS (1e-9)
#define PI (2*acos(0.0))
#define ll long long
#define ull unsigned ll
#define SIZE ((ll)1e8)+10
#define testcase ll T;cin>>T;for(int t=1;t<=T;t++)
#define printcase() cout<<"Case "<<t<<":\n"
#define pb push_back
#define PAR_SIZE 30010
#define BFS_GRID 1010
#define NL() cout << endl
#define FOR(itt,n) for(int itt=0;itt<n;++itt)
#define FOR1(itt,n) for(int itt=1;itt<=n;++itt)

bool vis[10000000];
int cost[10000000];
vector <int> adj[100005];

int ar[1000000];
int _max = 0;
int f;
void BFS(int s){
    f=s;
    vis[s]=true;
    cost[s]=0;
    _max=0;
    queue <int> Q;
    Q.push(s);
    while(!Q.empty()){
        int u = Q.front();
        Q.pop();
        vis[u]=true;
        FOR(i,adj[u].size()){
            int v = adj[u][i];
            if(!vis[v]){
                vis[v]=true;
                cost[v]=cost[u]+1;
                if(cost[v]>_max)f=v;
                _max = max(cost[v],_max);

                Q.push(v);
            }
        }
    }
}

int main()
{
    #ifdef pinanzo
        read();
        //freopen("output.txt","w",stdout);
    #endif // pinanzo
    //ios_base::sync_with_stdio(0);
    //cin.tie(NULL);
    //cout.tie(NULL);

    int n, m;
    scanf("%d %d", &n, &m);

    bool flag = true;

    FOR(i,m){
        int a, b;

        scanf("%d %d", &a, &b);
        ar[a]++;
        ar[b]++;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    int s;
    int mmm=-INF;
    FOR1(i,n){
        if(ar[i]==1){
            BFS(i);
            mmm = max(_max,mmm);
            FOR(i,n+1){
                vis[i]=false;
                cost[i]=0;
            }
            break;
        }
    }
    BFS(f);
    FOR(i,n+1){
        vis[i]=false;
        cost[i]=0;
    }
    BFS(f);
    printf("%d\n", _max);

    return 0;
}


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

#define read() freopen("input.txt","r",stdin)
#define INF ((1<<31)-1)
#define EPS (1e-9)
#define PI (2*acos(0.0))
#define ll long long
#define ull unsigned ll
#define SIZE ((ll)1e8)+10
#define testcase ll T;cin>>T;for(int t=1;t<=T;t++)
#define printcase() cout<<"Case "<<t<<":\n"
#define pb push_back
#define PAR_SIZE 30010
#define BFS_GRID 1010
#define NL() cout << endl
#define FOR(itt,n) for(int itt=0;itt<n;++itt)
#define FOR1(itt,n) for(int itt=1;itt<=n;++itt)

bool vis[10000000];
int cost[10000000];
vector <int> adj[100005];

int ar[1000000];
int _max = 0;

void BFS(int s){
    vis[s]=true;
    cost[s]=0;
    _max=0;
    queue <int> Q;
    Q.push(s);
    while(!Q.empty()){
        int u = Q.front();
        Q.pop();
        vis[u]=true;
        FOR(i,adj[u].size()){
            int v = adj[u][i];
            if(!vis[v]){
                vis[v]=true;
                cost[v]=cost[u]+1;
                _max = max(cost[v],_max);
                Q.push(v);
            }
        }
    }
}

int main()
{
    #ifdef pinanzo
        read();
        //freopen("output.txt","w",stdout);
    #endif // pinanzo
    //ios_base::sync_with_stdio(0);
    //cin.tie(NULL);
    //cout.tie(NULL);

    int n, m;
    scanf("%d %d", &n, &m);

    bool flag = true;

    FOR(i,m){
        int a, b;

        scanf("%d %d", &a, &b);
        ar[a]++;
        ar[b]++;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    int s;
    int mmm=-INF;
    FOR1(i,n){
        if(ar[i]==1){
            BFS(i);
            mmm = max(_max,mmm);
            FOR(i,n+1){
                vis[i]=false;
                cost[i]=0;
            }
        }
    }
    printf("%d\n", mmm);

    return 0;
}