#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];
queue <int> n;
int ar[1000000];

void BFS(int s){
    vis[s]=true;
    cost[s]=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;
                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;
    FOR1(i,n){
        if(ar[i]==1){
            s=i;
            break;
        }
    }
    BFS(s);
    int _min=-INF;
    FOR1(i,n){
        _min=max(cost[i],_min);
    }
    cout << _min << endl;

    return 0;
}


#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <bitset>
#include <functional>
#include <numeric>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <iterator>
#include <memory>
#include <utility>
#include <string>
#include <cassert>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define mset(a,b) memset(a,b,sizeof a)
#define mcpy(a,b) memcpy(a,b,sizeof a)
#define R(i,s,t) for(register int i=s;i<=t;++i)
#define Rd(i,s,t) for(register int i=s;i>=t;--i)
#define __ puts("")
#define _ putchar(' ')
#define all(T) T.begin(),T.end()

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
template <class T> T abs(T a){return a>=0?a:-a;}
template <class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template <class T> T mod(T a,T b){T ret=a%b;if(ret<0)ret+=b;return ret;}
ll mulmod(ll a,ll b,ll c){if(b==0LL)return 0LL;ll ret=mulmod(a,b>>1,c);ret=(ret+ret)%c;if(b&1LL)ret=(ret+a)%c;return ret;}
ll powmod(ll a,ll b,ll c){if(b==0LL)return 1LL;ll ret=powmod(a,b>>1,c);ret=ret*ret%c;if(b&1LL)ret=ret*a%c;return ret;}
template <class T> inline void write(T x){if (x<0)putchar('-'),x=-x;if (x<10)putchar(x + '0');else write(x / 10), putchar(x % 10 + '0');}
template <class T> inline void read(T&x){bool f=0; char ch;for(ch=getchar();ch<=32;ch=getchar());if (ch=='-')f=1,ch=getchar();for(x=0;ch>32;ch=getchar()) x =(x<<3)+(x<<1)+ch-'0';if(f) x=-x;}
//===========================================================================================

#define N 200005
#define inf 0x3f3f3f3f
using namespace std;
int n,cnt,ans,m;
int f1[N],f2[N],dfn[N],clk;
bool vis[N];
vii G[N];
stack<int>S;
void dfs() {
	S.push(1);
	dfn[1]=++clk;
	while(!S.empty()){
		int u=S.top();
		for(int i=0;i<int(G[u].size());++i){
			int v=G[u][i].X;
			if(dfn[v]==0){
				S.push(v);
				dfn[v]=++clk;
				break;
			}
		}
		if(S.top()==u){
			for(int i=0;i<int(G[u].size());++i){
				int v=G[u][i].X,w=G[u][i].Y;
				if(dfn[v]<=dfn[u])continue;
				if(f1[v]+w>f1[u]) {
					f2[u]=f1[u];
					f1[u]=f1[v]+w;
				} else f2[u]=max(f2[u],f1[v]+w);
			}
			ans=max(f1[u]+f2[u],ans);
			assert(!S.empty());
			S.pop();
		}
	}
}
int main() {
//	freopen("line.in","r",stdin);
//	freopen("line.out","w",stdout);
	read(n),read(m);int u,v,w;
	for(int i=1; i<=m; i++) {
		read(u),read(v),w=1;//,read(w);
		G[u].pb(mp(v,w));
		G[v].pb(mp(u,w));
	}
	dfs();
	write(ans),__;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define mset(a,b) memset(a,b,sizeof a)
#define mcpy(a,b) memcpy(a,b,sizeof a)
#define R(i,s,t) for(register int i=s;i<=t;++i)
#define Rd(i,s,t) for(register int i=s;i>=t;--i)
#define RR(i,a) for(register int i=0;i<int(a.size());++i)
#define __ puts("")
#define _ putchar(' ')
#define all(T) T.begin(),T.end()
#define g (c=getchar())
#define d isdigit(g)
#define p x=x*10+c-'0'
#define n x=x*10+'0'-c
#define pp l/=10,p
#define nn l/=10,n
#define sz(a) int(a.size())
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef double DB;
template <class T> T abs(T a){return a>=0?a:-a;}
template <class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template <class T> T mod(T a,T b){T ret=a%b;if(ret<0)ret+=b;return ret;}
ll mulmod(ll a,ll b,ll c){if(b==0LL)return 0LL;ll ret=mulmod(a,b>>1,c);ret=(ret+ret)%c;if(b&1LL)ret=(ret+a)%c;return ret;}
ll powmod(ll a,ll b,ll c){if(b==0LL)return 1LL;ll ret=powmod(a,b>>1,c);ret=ret*ret%c;if(b&1LL)ret=ret*a%c;return ret;}
template<class T> inline T& rd(T &x){char c;while(!d);x=c-'0';while(d)p;return x;}
template<class T> inline T& rdd(T &x){char c;while(g,c!='-'&&!isdigit(c));if (c=='-'){x='0'-g;while(d)n;}else{x=c-'0';while(d)p;}return x;}
inline double& rf(DB &x){char c;while(g,c!='-'&&c!='.'&&!isdigit(c));if(c=='-')if(g=='.'){x=0;DB l=1;while(d)nn;x*=l;}else{x='0'-c;while(d)n;if(c=='.'){DB l=1;while(d)nn;x*=l;}}else if(c=='.'){x=0;DB l=1;while(d)pp;x*=l;}else{x=c-'0';while(d)p;if(c=='.'){DB l=1;while(d)pp;x*=l;}}return x;}
#undef nn
#undef pp
#undef n
#undef p
#undef d
#undef g
/* .................................................................................................................................. */

int main(){
	#ifdef Arch0n
		freopen("in.txt","r",stdin);
		freopen("out.txt","w",stdout);
	#endif
	int n,m;rd(n),rd(m);cout<<m-1;

	return 0;
}
/*

*/


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<cmath>
#include<cctype>
#include<ctime>
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define MOD 998244353
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

vector<int> G[100005];
bool vis[100005];
int maxm=0,ans=1;

int dfs(int k,int num)
{
	if(maxm<num)
	{
		maxm=num;
		ans=k;
	}
	for(int i=0;i<G[k].size();i++)
	{
		int kk=G[k][i];
		if(!vis[kk])
		{
			vis[kk]=1;
			dfs(kk,num+1);
		}
	}
}

int main()
{
	int n,m;
	cin>>n>>m;
	memset(vis,0,sizeof(vis));
	for(int i=0;i<m;i++)
	{
		int u,v;
		cin>>u>>v;
		G[v].push_back(u);
		G[u].push_back(v);
	}
	vis[1]=1;
	dfs(1,0);
	memset(vis,0,sizeof(vis));
	vis[ans]=1;
	maxm=0;
	dfs(ans,0);
	cout<<maxm;
	return 0;
}


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

#define N 100005
vector<int> adj[N];

//functions as defined above
int dp1[N],dp2[N];

//pV is parent of node V
void dfs(int V, int pV)
{
	//for storing sums of dp1 and max(dp1, dp2) for all children of V
    int sum1=0, sum2=0,v,sum3=0;

    //traverse over all children
    for(int k=0;k<adj[V].size();k++)
    {
    	v=adj[V][k];
	    if(v == pV) continue;

	    dfs(v, V);
	    sum1 =max(sum1,dp1[v]);

	    if(dp2[v]>sum3)
	    {
	    	if(dp2[v]>sum2)
	    	{
	    		sum3=sum2;
	    		sum2=dp2[v];
	    	}
	    	else
	    	{
	    		sum3=dp2[v];
	    	}
	    }
    }

    dp1[V] = max(sum1,sum2+sum3+1);
    dp2[V] = sum2+1;
}

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

	int u,v;

    for(int i=1; i<n; i++)
    {
	    cin >> u >> v;
	    adj[u].push_back(v);
	    adj[v].push_back(u);
    }

    dfs(1, 0);
    int ans = dp1[1]-1;

    cout << ans << endl;
}


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

#define N 10005
vector<int> adj[N];

//functions as defined above
int dp1[N],dp2[N];

//pV is parent of node V
void dfs(int V, int pV)
{
	bool flag=false;
    //for storing sums of dp1 and max(dp1, dp2) for all children of V
    int sum1=0, sum2=0,v,sum3=0;

    //traverse over all children
    for(int k=0;k<adj[V].size();k++)
    {
    	v=adj[V][k];
	    if(v == pV) continue;
	    flag=true;
	    dfs(v, V);
	    sum1 =max(sum1,dp1[v]);

	    if(dp2[v]>sum3)
	    {
	    	if(dp2[v]>sum2)
	    	{
	    		sum3=sum2;
	    		sum2=dp2[v];
	    	}
	    	else
	    	{
	    		sum3=dp2[v];
	    	}
	    }
    }

    dp1[V] = max(sum1,sum2+sum3+1);
    dp2[V] = sum2+1;

}

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

	int u,v;

    for(int i=1; i<n; i++)
    {
	    cin >> u >> v;
	    adj[u].push_back(v);
	    adj[v].push_back(u);
    }

    dfs(1, 0);
    int ans = dp1[1]-1;

    cout << ans << endl;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef long double ldb;

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define all(v) (v).begin(),(v).end()
#define dbg(a) cout << #a << " = " << a << endl

vector<vector<int> > d(100001);
vector<int> dist;
vector<bool> used;
queue<int> q;

void bfs(int s) {
	q.push(s);
	used[s] = true;
	dist[s] = 0;
	while(!q.empty()) {
		int v = q.front();
		q.pop();
		for(int i = 0; i < d[v].size(); i++) {
			int to = d[v][i];
			if(!used[to] && dist[to] == -1) {
				q.push(to);
				dist[to] = dist[v] + 1;
				used[to] = true;
			}
		}
	}
}

int main() {

	ios_base::sync_with_stdio(false);
    cin.tie(0);

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n,m;
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		d[u].pb(v);
		d[v].pb(u);
	}
	dist.assign(n, -1);
	used.assign(n, false);
	bfs(0);
	int mn = 0;
	for(int i = 0; i < n; i++) {
		if(dist[i] > dist[mn]) {
			mn = i;
		}
	}
	dist.assign(n, -1);
	used.assign(n, false);
	bfs(mn);
	int ans = 0;
	for(int i = 0; i < n; i++) {
		ans = max(ans, dist[i]);
	}

	cout << ans;
	return 0;
}


/*
    Author: Nishat Tasnim Ahmed Meem
    Shahjalal University Of Science & Technology, '13batch
*/

#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<sstream>
#include<set>
#include<utility>

using namespace std;

#define inf 1<<28
#define ll long long
#define sf1(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d %d",&a,&b)
#define sf3(a,b,c) scanf("%d %d %d", &a,&b, &c)
#define sf4(a,b,c, d) scanf("%d %d %d %d", &a,&b, &c, &d)
#define sf1ll(a) scanf("%lld",&a)
#define sf2ll(a,b) scanf("%lld %lld",&a,&b)
#define sf3ll(a,b,c) scanf("%lld %lld %lld", &a,&b, &c)
#define sf4ll(a,b,c, d) scanf("%lld %lld %lld %lld", &a,&b, &c, &d)
#define pi acos(-1)
#define pii pair<int, int>
#define clr(a) memset(a, 0, sizeof a)
#define clr1(a) memset(a, -1, sizeof a)

template<class T> T power(T N,T P)
{
    return (P==0)?  1: N*power(N,P-1);   //N^P
}
template<class T> T gcd(T a,T b)
{
    if(b == 0)return a;    //gcd(a,b)
    return gcd(b,a%b);
}

template<class T1> void deb(T1 e1)
{
    cout<<e1<<endl;
}
template<class T1,class T2> void deb(T1 e1,T2 e2)
{
    cout<<e1<<" "<<e2<<endl;
}
template<class T1,class T2,class T3> void deb(T1 e1,T2 e2,T3 e3)
{
    cout<<e1<<" "<<e2<<" "<<e3<<endl;
}
template<class T1,class T2,class T3,class T4> void deb(T1 e1,T2 e2,T3 e3,T4 e4)
{
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<endl;
}
template<class T1,class T2,class T3,class T4,class T5> void deb(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5)
{
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<endl;
}
template<class T1,class T2,class T3,class T4,class T5,class T6> void deb(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6)
{
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<" "<<e6<<endl;
}

//ll BigMod(ll B,ll P,ll M){ ll R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M

//ll gcd(ll a,ll b){if(b == 0)return a;return gcd(b,a%b);}
//ll lcm(ll a,ll b){return (a/gcd(a,b))*b;}

//int Set(int N,int pos){return N=N | (1<<pos);}
//int Reset(int N,int pos){return N= N & ~(1<<pos);}
//bool Check(int N,int pos){return (bool)(N & (1<<pos));}
//N & (N % 2 ? 0 : ~0) | ( ((N & 2)>>1) ^ (N & 1) )://XOR of 1-n numbers

int dx[] = { 0, 1,  0, -1, -1, 1,  1, -1 };
int dy[] = { 1, 0, -1,  0,  1, 1, -1, -1 };
int xx[] = { -1, 1, 2, 2,  1, -1, -2, -2 };
int yy[] = {  2, 2, 1,-1, -2, -2, -1,  1 };

#define sz 100010

int ans, u, dist[sz];
vector<int>vec[sz];

void BFS()
{
    memset(dist, -1, sizeof dist);
    queue<int>qu;
    dist[u] = 0;
    qu.push(u);
    ans = 0;

    while(qu.size())
    {
        int v = qu.front();
        qu.pop();
        for(int i=0; i<vec[v].size(); i++)
        {
            int w = vec[v][i];
            if(dist[w] == -1)
            {
                dist[w] = dist[v] + 1;
                qu.push(w);
                if(dist[w]>ans)
                {
                    ans = dist[w];
                    u = w;
                }
            }
        }
    }

}

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

    int n, m, i, j, x, y;

    while(sf2(n, m) == 2)
    {
        for(i=0; i<=n; i++) vec[i].clear();

        while(m--)
        {
            sf2(x, y);
            vec[x].push_back(y);
            vec[y].push_back(x);
        }
        u = 1;
        BFS();
        BFS();
        printf("%d\n", ans);
    }

    return 0;
}


/*
 * File:   690C2.cpp
 * Author: urby7
 *
 * Created on July 29, 2016, 4:35 PM
 */

#include <cstdlib>
#include <list>
#include <queue>
#include <iostream>
using namespace std;

/*
 *
 */

int maxIndex (int *a, int len){
    int index, max = 0;

    for(int i = 0; i < len; i++){
        if(a[i] > max){
            index = i;
            max = a[i];
        }
    }

    return index;
}

int main(int argc, char** argv) {
    int n, m, x, y;
    cin>>n>>m;

    list<int> *adj = new list<int>[n];
    queue<int> q;
    short col[n];
    int dist[n];

    for(int i = 0; i < n; i++){
        col[i] = 0;
    }

    for(int i = 0; i < m; i++){
        cin>>x>>y;
        adj[x-1].push_back(y-1);
        adj[y-1].push_back(x-1);
    }

    q.push(0);
    dist[0] = 0;

    while(!q.empty()){
        x = q.front();
        q.pop();
        col[x] = 2;
        for(list<int>::iterator it = adj[x].begin(); it != adj[x].end(); it++){
            if(col[*it] == 0){
                col[*it] = 1;
                dist[*it] = dist[x] + 1;
                q.push(*it);
            }
        }
    }

    int src = maxIndex(dist, n);

    for(int i = 0; i < n; i++){
        col[i] = 0;
    }

    q.push(src);
    dist[src] = 0;

    while(!q.empty()){
        x = q.front();
        q.pop();
        col[x] = 2;
        for(list<int>::iterator it = adj[x].begin(); it != adj[x].end(); it++){
            if(col[*it] == 0){
                col[*it] = 1;
                dist[*it] = dist[x] + 1;
                q.push(*it);
            }
        }
    }

    cout<<dist[maxIndex(dist, n)];

    return 0;
}


#include<cstdio>
#include<cstring>
struct edge{int to;edge*next;}e[200010],*la[100010],*et=e;
void add(int u,int v){
	*++et=(edge){v,la[u]},la[u]=et;
	*++et=(edge){u,la[v]},la[v]=et;
}
int q[1<<22],l,r,n,vis[100010],ye[100010];
const int oo=1e9;
int bfs(int s,int*d){
	l=r=0,q[r++]=s;
	memset(d,63,sizeof(int)*(n+10));
	memset(vis,0,sizeof(int)*(n+10));
	d[s]=0;vis[s]=1;ye[s]=1;
	while(l<r){
		int u=q[l++];
		for(edge*it=la[u];it;it=it->next)
		if(d[u]+1<d[it->to])
		ye[it->to]=1,d[it->to]=d[u]+1,vis[it->to]?:(vis[it->to]=1,q[r++]=it->to);
		vis[u]=0;
	}
	int k=s;
	for(int i=1;i<=n;i++)d[k]<d[i]&&d[i]<oo?k=i:1;
	return k;
}
int F(){char c;int x;while(c=getchar(),c<'0'||c>'9');x=c-'0';
while(c=getchar(),c>='0'&&c<='9')x=x*10+c-'0';return x;
}
int d[100010];
int main(){
	int ans=0;
	n=F();for(int m=F(),u,v;m--;)u=F(),v=F(),add(u,v);
	for(int i=1;i<=n;i++)
		if(!ye[i]){
			int k=bfs(i,d),c=bfs(k,d);
			ans<d[c]?ans=d[c]:1;
		}
	return!printf("%d\n",ans);
}


#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <iomanip>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <sstream>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>

using namespace std;
int n,m,g;
vector<vector<int> >graph(100000);
int visited[100000];

struct node{
int len;
int index;
};

int dfs(int start){
    memset(visited,0,4*n);
    stack<node>stek;
    node temp,top;
    temp.len=0;
    temp.index=start;
    visited[start]=1;
    int r=0,m=0;
    stek.push(temp);
    while(!stek.empty()){
        top=stek.top();
        stek.pop();
        if(top.len>m)
        {
            m=top.len;
            r=top.index;
        }
        temp.len=top.len+1;
            for(int i=0; i<graph[top.index].size(); i++){
            int index=graph[top.index][i];
            if(!visited[index]){
                visited[index]=1;
                temp.index=index;
                stek.push(temp);
            }
        }

    }
    g=m;
    return r;

}

int main(){
    ios_base::sync_with_stdio(false);
int u,v;
cin>>n>>m;
for(int i=0; i<m; i++){
    cin>>u>>v;
    graph[u-1].push_back(v-1);
    graph[v-1].push_back(u-1);
}
dfs(dfs(u-1));
cout<<g;

return 0;}


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <iomanip>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <sstream>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>

using namespace std;

struct node{
int len;
int index;
};

int main(){
    ios_base::sync_with_stdio(false);
    int n,m,u,v,min=INT_MAX,max=0;
    cin>>n>>m;
    vector<vector<int> >brain(n);
    int visited[n];
    memset(visited,0,sizeof(visited));
    for(int i=0; i<m; i++){
        cin>>u>>v;
        brain[u-1].push_back(v-1);
        brain[v-1].push_back(u-1);
    }
    node temp,top;
    temp.index=u-1;
    temp.len=0;
    visited[temp.index]=1;
    if(brain[temp.index].size()==1)
        min=0;
    stack<node>stek;
    stek.push(temp);
    while(!stek.empty()){
        top=stek.top();
        stek.pop();
        temp.len=top.len+1;
        if(brain[top.index].size()==1 && visited[brain[top.index][0]]){
            if(top.len>max)
                max=top.len;
            else if(top.len<min)
                min=top.len;
        }
        else{
                for(int i=0; i<brain[top.index].size(); i++){
                int num=brain[top.index][i];
            if(!visited[num]){
                    visited[num]=1;
                temp.index=num;
                stek.push(temp);

            }
        }

        }

    }
    cout<<max+min;

return 0;}


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <iomanip>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <sstream>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>

using namespace std;

struct node{
int len;
int index;
};

int main(){
    ios_base::sync_with_stdio(false);
    int n,m,u,v,min=INT_MAX,max=0;
    cin>>n>>m;
    vector<vector<int> >brain(n);
    int visited[n],lengths[n];
    memset(visited,0,sizeof(visited));
    for(int i=0; i<m; i++){
        cin>>u>>v;
        brain[u-1].push_back(v-1);
        brain[v-1].push_back(u-1);
    }
    node temp,top;
    temp.index=u-1;
    lengths[temp.index]=temp.len=0;
    if(brain[temp.index].size()==1)
        min=0;
    stack<node>stek;
    stek.push(temp);
    while(!stek.empty()){
        top=stek.top();
        stek.pop();
        temp.len=top.len+1;
        if(brain[top.index].size()==1){
            if(top.len>max)
                max=top.len;
            else if(top.len<min)
                min=top.len;
        }
        else{
                for(int i=0; i<brain[top.index].size(); i++){
                int num=brain[top.index][i];
            if(!visited[num]){
                    visited[num]=1;
                lengths[num]=temp.len;
                temp.index=num;
                stek.push(temp);

            }
        }

        }

    }
    cout<<max+min;

return 0;}


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <iomanip>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <sstream>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>

using namespace std;

struct node{
int len;
int index;
};

int main(){
    ios_base::sync_with_stdio(false);
    int n,m,u,v,max=0;
    cin>>n>>m;
    vector<vector<int> >brain(n);
    int visited[n];
    memset(visited,0,sizeof(visited));
     node temp,top;
    for(int i=0; i<m; i++){
        cin>>u>>v;
        brain[u-1].push_back(v-1);
        brain[v-1].push_back(u-1);
    }
    for(int i=0; i<n; i++)
    if(brain[i].size()==1){
        temp.index=i;
        break;
    }
    temp.len=0;
    visited[temp.index]=1;
    stack<node>stek;
    stek.push(temp);
    while(!stek.empty()){
        top=stek.top();
        stek.pop();
        temp.len=top.len+1;
        if(brain[top.index].size()==1 && visited[brain[top.index][0]]){
            if(top.len>max)
                max=top.len;
        }
        else{
                for(int i=0; i<brain[top.index].size(); i++){
                int num=brain[top.index][i];
            if(!visited[num]){
                    visited[num]=1;
                temp.index=num;
                stek.push(temp);

            }
        }

        }

    }
    cout<<max;

return 0;}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
const int maxn=100000+5;
vector<int> G[maxn];
int _max,flag;
void dfs(int u,int fa,int dep)
{
    for(int i=0;i<G[u].size();i++)
    {
        int v=G[u][i];
        if(v==fa) continue;
        if(dep+1>_max)
        {
            _max=dep+1;
            flag=v;
        }
        dfs(v,u,dep+1);
    }
}
void init()
{
    for(int i=0;i<maxn;i++) G[i].clear();
    _max=0,flag=-1;
}
int main()
{
    //freopen("in.txt","r",stdin);
    int n,m;
    while(~scanf("%d%d",&n,&m))
    {
        init();
        for(int i=0;i<m;i++)
        {
            int p,q;
            scanf("%d%d",&p,&q);
            G[p].push_back(q);
            G[q].push_back(p);
        }
        dfs(1,-1,0);
        _max=0;
        dfs(flag,-1,0);
        printf("%d\n",_max);
    }
}


#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std ;

#define MAXN 500007

int n , m ;
vector < int > v[ MAXN ] ;
int used[ MAXN ] ;

void dfs ( int vertex , int pr ) {
	used[ vertex ] = used[ pr ] + 1 ;
	int i ;
	int sz = v[ vertex ].size ( ) ;
	for ( i = 0 ; i < sz ; i ++ ) {
		if ( used[ v[ vertex ][ i ] ] == 0 ) {
			dfs ( v[ vertex ][ i ] , vertex ) ;
		}
	}
}

void input ( ) {
	scanf ( "%d%d" , &n , &m ) ;
	int i ;
	int x , y ;
	for ( i = 1 ; i <= m ; i ++ ) {
		scanf ( "%d%d" , &x , &y ) ;
		v[ x ].push_back ( y ) ;
		v[ y ].push_back ( x ) ;
	}
}

void solve ( ) {
	int i ;
	dfs ( 1 , 0 ) ;
	int mx = -1 ;
	int id = -1 ;
	for ( i = 1 ; i <= n ; i ++ ) {
		if ( mx < used[ i ] ) { mx = used[ i ] ; id = i ; }
		used[ i ] = 0 ;
	}
	dfs ( id , 0 ) ;
	mx = -1 ;
	id = -1 ;
	for ( i = 1 ; i <= n ; i ++ ) {
		if ( mx < used[ i ] ) { mx = used[ i ] ; id = i ; }
		used[ i ] = 0 ;
	}
	printf ( "%d\n" , ( mx - 1 ) ) ;
}

int main ( ) {
	input ( ) ;
	solve ( ) ;
	return 0 ;
}


#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std ;

#define MAXN 1007

int n , m ;
vector < int > v[ MAXN ] ;
int used[ MAXN ] ;

void dfs ( int vertex , int pr ) {
	used[ vertex ] = used[ pr ] + 1 ;
	int i ;
	int sz = v[ vertex ].size ( ) ;
	for ( i = 0 ; i < sz ; i ++ ) {
		if ( used[ v[ vertex ][ i ] ] == 0 ) {
			dfs ( v[ vertex ][ i ] , vertex ) ;
		}
	}
}

void input ( ) {
	scanf ( "%d%d" , &n , &m ) ;
	int i ;
	int x , y ;
	for ( i = 1 ; i <= m ; i ++ ) {
		scanf ( "%d%d" , &x , &y ) ;
		v[ x ].push_back ( y ) ;
		v[ y ].push_back ( x ) ;
	}
}

void solve ( ) {
	int i ;
	dfs ( 1 , 0 ) ;
	int mx = -1 ;
	int id = -1 ;
	for ( i = 1 ; i <= n ; i ++ ) {
		if ( mx < used[ i ] ) { mx = used[ i ] ; id = i ; }
		used[ i ] = 0 ;
	}
	dfs ( id , 0 ) ;
	mx = -1 ;
	id = -1 ;
	for ( i = 1 ; i <= n ; i ++ ) {
		if ( mx < used[ i ] ) { mx = used[ i ] ; id = i ; }
		used[ i ] = 0 ;
	}
	printf ( "%d\n" , ( mx - 1 ) ) ;
}

int main ( ) {
	input ( ) ;
	solve ( ) ;
	return 0 ;
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define MAX 100005
#define mod 1000000007
using namespace std;
vector<int>v[MAX];
int d[MAX];
bool visited[MAX];
void bfs(int source)
{
    queue<int>q;
    d[source]=0;
    q.push(source);
    visited[source]=true;
    int cur,i;
    while(!q.empty())
    {
        cur=q.front();  q.pop();
        for(i=0;i<v[cur].size();i++)
            if(!visited[v[cur][i]])
             {
                 q.push(v[cur][i]);
                 d[v[cur][i]]=d[cur]+1;
                 visited[v[cur][i]]=true;
             }
    }
}
main()
{
    std::ios::sync_with_stdio(false);
    int n,m,i,j,a,b,maxx,maxi;
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    bfs(1);
    maxx=d[1];maxi=1;
    for(i=2;i<=n;i++)
        if(d[i]>maxx)
        {
            maxx=d[i];
            maxi=i;
        }
    for(i=1;i<=n;i++)
        visited[i]=false;
    bfs(maxi);
    maxx=d[1];
    for(i=2;i<=n;i++)
        if(d[i]>maxx)
            maxx=d[i];
    cout<<maxx;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

typedef std::vector<bool> VecBool;
typedef std::vector<int> VecInt;
typedef std::vector<VecInt> Graph;

class Problem
{
public:
	void init();
	void solve();

private:
	void m_dfs(int from, int deep);

	int m_n;
	int m_m;
	int m_node;
	int m_deep;
	Graph m_g;
	VecBool m_used;
};

int main()
{
	Problem p;

	p.init();
	p.solve();

	return 0;
}

void Problem::init()
{
	std::cin >> m_n >> m_m;

	m_g.resize(m_n);

	for (int i = 0; i < m_m; ++i)
	{
		int a;
		int b;

		std::cin >> a >> b;

		--a;
		--b;

		m_g[a].push_back(b);
		m_g[b].push_back(a);
	}

	m_node = 0;
	m_deep = 0;
}

void Problem::solve()
{
	m_used.resize(m_n, false);
	m_dfs(m_node, 0);
	m_used.assign(m_n, false);
	m_dfs(m_node, 0);

	std::cout << m_deep << std::endl;
}

void Problem::m_dfs(int from, int deep)
{
	m_used[from] = true;

	if (deep > m_deep)
	{
		m_deep = deep;
		m_node = from;
	}

	for (int i = 0; i < m_g[from].size(); ++i)
	{
		int to = m_g[from][i];

		if (!m_used[to])
			m_dfs(to, deep + 1);
	}
}


#include<bits/stdc++.h>

using namespace std;

vector<int>g[100005];
bool vis[100005];
int dep[100005];

int main() {
  //freopen("in.txt","r",stdin);
  int n, m;
  scanf("%d%d",&n,&m);
  int x, y;
  for(int i=1;i<n;i++) {
    scanf("%d%d",&x,&y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  queue<int>q;
  q.push(1);
  vis[1] = 1;
  int rt = 1;
  while(!q.empty()) {
    int x = q.front();q.pop();
    rt = x;
    for(int i=0;i<g[x].size();i++) {
      int y = g[x][i];
      if(vis[y]) continue;
      vis[y] = 1;
      q.push(y);
    }
  }
  dep[rt] = 1;
  memset(vis,0,sizeof(vis));
  vis[rt] = 1;
  q.push(rt);
  int ans = 1;
  while(!q.empty()) {
    int x = q.front();q.pop();
    rt = x;
    for(int i=0;i<g[x].size();i++) {
      int y = g[x][i];
      if(vis[y]) continue;
      vis[y] = 1;
      dep[y] = dep[x]+1;
      ans = max(ans, dep[y]);
      q.push(y);
    }
  }
  printf("%d\n",ans);
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

vector<int>g[100005];
bool vis[100005];
int dep[100005];

int main() {
  //freopen("in.txt","r",stdin);
  int n, m;
  scanf("%d%d",&n,&m);
  int x, y;
  for(int i=1;i<n;i++) {
    scanf("%d%d",&x,&y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  queue<int>q;
  q.push(1);
  vis[1] = 1;
  int rt = 1;
  while(!q.empty()) {
    int x = q.front();q.pop();
    rt = x;
    for(int i=0;i<g[x].size();i++) {
      int y = g[x][i];
      if(vis[y]) continue;
      vis[y] = 1;
      q.push(y);
    }
  }
  dep[rt] = 1;
  memset(vis,0,sizeof(vis));
  vis[rt] = 1;
  q.push(rt);
  int ans = 1;
  while(!q.empty()) {
    int x = q.front();q.pop();
    rt = x;
    for(int i=0;i<g[x].size();i++) {
      int y = g[x][i];
      if(vis[y]) continue;
      vis[y] = 1;
      dep[y] = dep[x]+1;
      ans = max(ans, dep[y]);
      q.push(y);
    }
  }
  printf("%d\n",ans-1);
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define mod 1000000007
#define bitcount __builtin_popcountll
#define ll long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pi,int>
#define mp make_pair
int ans;
vector<int>v[100005];
int dfs(int node, int par)
{
	vector<int>temp;
	temp.pb(0);
	temp.pb(0);
	for(int i=0;i<v[node].size();i++)
	{
		if(v[node][i]!=par)
		{
			temp.pb(dfs(v[node][i],node));
		}
	}
	sort(temp.begin(), temp.end());
	ans=max(ans,temp[temp.size()-1]+temp[temp.size()-2]+1);
	return temp[temp.size()-1]+1;
}
int main()
{
	int i,j,k;
	ans=0;
	int n,m;
	sd(n);
	sd(m);
	for(i=0;i<m;i++)
	{
		sd(j);
		sd(k);
		v[j].pb(k);
		v[k].pb(j);
	}
	dfs(1,-1);
	printf("%d\n",ans-1 );
	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <deque>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#include <complex>
#include <cstring>
#include <bitset>
//#include "sdf.hpp"

using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define repd(i, a, b) for(int i = (a); i > (b); i--)
#define forIt(it, a) for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define forRev(it, a) for(__typeof((a).rbegin()) it = (a).rbegin(); it != (a).rend(); it++)
#define ft(a) __typeof((a).begin())
#define ll long long
#define ld long double
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define sz(a) (a).size()
#define all(a) (a).begin(), (a).end()
#define Rep(i,n) for(int i = 0; i < (n); ++i)

typedef complex<ld> cplex;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

const int N = 200000 + 7;
const int M = 59;
const int mid = M / 2;
const int mod = 1e9 + 9;
const int inf = 1e9 + 7;
const ll linf = 1ll * inf * inf;
const double pi = acos(-1);
const double eps = 1e-7;
const double ep = 1e-5;
const int maxn = 1e5 + 7;
const double PI = acos(-1);

int n, m;

vi adj[N];
int d[N];

void DFS(int u, int r) {
    rep(j, 0, adj[u].size()) {
        int v = adj[u][j];
        if (v != r) {
            d[v] = d[u] + 1;
            DFS(v, u);
        }
    }
}

void solve() {
    cin >> n >> m;
    rep(t, 0, m) {
        int u, v;
        scanf("%d%d", &u, &v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    DFS(1, -1);
    int mx = 1;
    rep(u, 1, n + 1) if (d[mx] < d[u]) mx = u;
    DFS(mx, -1);
    rep(u, 1, n + 1) if (d[mx] < d[u]) mx = u;
    cout << d[mx];
}

int main() {
#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout);
#endif
    int T = 1;
    //cin >>T;
    //cout << T << "\n";
    rep(i, 1, T + 1) {
        //printf("Case #%d: ", 1i);
        //        m = i;
        solve();
        //cout << prime.size() << "\n";
    }

}


#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <deque>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#include <complex>
#include <cstring>
#include <bitset>
//#include "sdf.hpp"

using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define repd(i, a, b) for(int i = (a); i > (b); i--)
#define forIt(it, a) for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define forRev(it, a) for(__typeof((a).rbegin()) it = (a).rbegin(); it != (a).rend(); it++)
#define ft(a) __typeof((a).begin())
#define ll long long
#define ld long double
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define sz(a) (a).size()
#define all(a) (a).begin(), (a).end()
#define Rep(i,n) for(int i = 0; i < (n); ++i)

typedef complex<ld> cplex;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

const int N = 200000 + 7;
const int M = 59;
const int mid = M / 2;
const int mod = 1e9 + 9;
const int inf = 1e9 + 7;
const ll linf = 1ll * inf * inf;
const double pi = acos(-1);
const double eps = 1e-7;
const double ep = 1e-5;
const int maxn = 1e5 + 7;
const double PI = acos(-1);

int n, m;

vi adj[N];
int d[N];

void DFS(int u, int r) {
    rep(j, 0, adj[u].size()) {
        int v = adj[u][j];
        if (v != r) {
            d[v] = d[u] + 1;
            DFS(v, u);
        }
    }
}

void solve() {
    cin >> n >> m;
    rep(t, 0, m) {
        int u, v;
        scanf("%d%d", &u, &v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    DFS(1, -1);
    int mx = 1;
    rep(u, 1, n + 1) if (d[mx] < d[u]) mx = u;
    d[mx] = 0;
    DFS(mx, -1);
    rep(u, 1, n + 1) if (d[mx] < d[u]) mx = u;
    cout << d[mx];
}

int main() {
#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout);
#endif
    int T = 1;
    //cin >>T;
    //cout << T << "\n";
    rep(i, 1, T + 1) {
        //printf("Case #%d: ", 1i);
        //        m = i;
        solve();
        //cout << prime.size() << "\n";
    }

}


#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <deque>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#include <complex>
#include <cstring>
#include <bitset>
//#include "sdf.hpp"

using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define repd(i, a, b) for(int i = (a); i > (b); i--)
#define forIt(it, a) for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define forRev(it, a) for(__typeof((a).rbegin()) it = (a).rbegin(); it != (a).rend(); it++)
#define ft(a) __typeof((a).begin())
#define ll long long
#define ld long double
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define sz(a) (a).size()
#define all(a) (a).begin(), (a).end()
#define Rep(i,n) for(int i = 0; i < (n); ++i)

typedef complex<ld> cplex;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

const int N = 1000000 + 7;
const int M = 59;
const int mid = M / 2;
const int mod = 1e9 + 9;
const int inf = 1e6 + 3;
const ll linf = 1ll * inf * inf;
const double pi = acos(-1);
const double eps = 1e-7;
const double ep = 1e-5;
const int maxn = 1e5 + 7;
const double PI = acos(-1);

int lt[N], invlt[N];

int inverse(int x, int n){
    int r = n, newr = x;
    int t = 0, newt = 1;
    while (newr > 0){
        int q = r / newr;
        int tmp = newr;
        newr = r % newr;
        r = tmp;

        tmp = newt;
        newt = t - q * newt;
        t = tmp;
    }
    if (t < 0) t += n;
    return t;
}

void init() {
    lt[0] = invlt[0] = 1;
    rep(i, 1, N) {
        lt[i] = (ll) lt[i - 1] * i % inf;
        invlt[i] = inverse(lt[i], inf);
    }
}

int C(int n, int k) {
    return (ll) lt[n] * invlt[n - k] % inf * invlt[k] % inf;
}

void solve() {
    init();
    int ans = 0;
    int n, k;
    cin >> n >> k;
    rep(i, 1, n + 1) {
        ans = (ans + C(i + k - 1, i)) % inf;
    }
    cout << ans;
}

int main() {
#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout);
#endif
    int T = 1;
    //cin >>T;
    //cout << T << "\n";
    rep(i, 1, T + 1) {
        //printf("Case #%d: ", 1i);
        //        m = i;
        solve();
        //cout << prime.size() << "\n";
    }

}


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

typedef struct lnod {
     int info;
     lnod *next;
}*nod;

int i,n,m,x,y,s,rs,a[100005];
nod lda[100005];

void add(int x,nod &y)
{
  nod p=new lnod;
  p->info=x;
  p->next=y;
  y=p;
}

void dfs(int x,int tata)
{
  for(nod p=lda[x];p;p=p->next)
  if(a[p->info]==0 && p->info!=tata) {a[p->info]=a[x]+1; dfs(p->info,x);  }
}
int main()
{
  ios_base::sync_with_stdio(0);

  cin>>n>>m;

  for(i=1;i<=m;i++)
  {
    cin>>x>>y;
    add(x,lda[y]);
    add(y,lda[x]);
  }

  dfs(1,1); rs=0;
  for(i=1;i<=n;i++)
  if(a[i]>a[rs]) rs=i;

  memset(a,0,sizeof(a));
  dfs(rs,rs); rs=0;
  for(i=1;i<=n;i++)
  if(a[i]>rs) rs=a[i];

  cout<<rs;

 return 0;
}


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

typedef struct lnod {
     int info;
     lnod *next;
}*nod;

int i,n,m,x,y,s,rs,a[100005];
nod lda[100005];

void add(int x,nod &y)
{
  nod p=new lnod;
  p->info=x;
  p->next=y;
  y=p;
}

void dfs(int x)
{
  nod p=new lnod;
  for(p=lda[x];p;p=p->next)
  if(a[p->info]==0) {a[p->info]=a[x]+1; dfs(p->info);  }
}
int main()
{
  ios_base::sync_with_stdio(0);

  cin>>n>>m;

  for(i=1;i<=m;i++)
  {
    cin>>x>>y;
    add(x,lda[y]);
    add(y,lda[x]);
  }

  dfs(1); rs=0;
  for(i=1;i<=n;i++)
  if(a[i]>a[rs]) rs=i;

  memset(a,0,sizeof(a));
  dfs(rs); rs=0;
  for(i=1;i<=n;i++)
  if(a[i]>rs) rs=a[i];

  cout<<rs;

 return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

typedef pair <int, int> ii;

const int Maxn = 100005;

int n, m;
vector <int> neigh[Maxn];
ii mx[Maxn];

void Traverse(int v, int l = 0, int p = 0)
{
	mx[v] = ii(l, v);
	for (int i = 0; i < neigh[v].size(); i++) {
		int u = neigh[v][i];
		if (u == p) continue;
		Traverse(u, l + 1, v);
		mx[v] = max(mx[v], mx[u]);
	}
}

int main()
{
	scanf("%d %d", &n, &m);
	while (m--) {
		int a, b; scanf("%d %d", &a, &b);
		neigh[a].push_back(b);
		neigh[b].push_back(a);
	}
	Traverse(1);
	int r = mx[1].second;
	Traverse(r);
	printf("%d\n", mx[r].first);
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

vector <int> adj[100007];
int vis[100007],dis[100007];

int bfs(int n)
{
    memset(vis,0,sizeof vis);
    memset(dis,0,sizeof dis);
    queue<int> q;
    int mx=-1,point;
    q.push(n);
    dis[n]=0;
    while(!q.empty())
    {
        int u=q.front();
        vis[u]=1;
        q.pop();
        for(int i=0;i<adj[u].size();i++)
        {
            int v=adj[u][i];
            if(!vis[v])
            {
                q.push(v);
                dis[v]=dis[u]+1;
                if(dis[v]>mx)
                {
                    mx=dis[v];
                    point=v;
                }
            }
        }
    }
    return point;
}

int rebfs(int n)
{
    memset(vis,0,sizeof vis);
    memset(dis,0,sizeof dis);
    queue<int> q;
    int mx=-1,point;
    q.push(n);
    dis[n]=0;
    while(!q.empty())
    {
        int u=q.front();
        vis[u]=1;
        q.pop();
        for(int i=0;i<adj[u].size();i++)
        {
            int v=adj[u][i];
            if(!vis[v])
            {
                q.push(v);
                dis[v]=dis[u]+1;
                if(dis[v]>mx)
                {
                    mx=dis[v];
                    point=v;
                }
            }
        }
    }
    return mx;
}

int main()
{
    int node,edg;
    cin>>node>>edg;
    for(int i=1;i<=edg;i++)
    {
        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    cout<<rebfs(bfs(1))<<endl;
    return 0;
}


/* -------------------------------- */
/* Name: MD. Khairul Basar          */
/* Institute: HSTU                  */
/* Dept: CSE                        */
/* Email: khairul.basar93@gmail.com */
/* -------------------------------- */

#include <bits/stdc++.h>
/* all header files included */

#define fs            first
#define sc            second
#define sp            printf(" ")
#define nl            printf("\n")
#define pb(a)         push_back(a)
#define mp(a,b)       make_pair(a,b)

#define setzero(a)    memset(a,0,sizeof(a))
#define setneg(a)     memset(a,-1,sizeof(a))
#define setinf(a)     memset(a,126,sizeof(a))

#define tc1(x)        printf("Case %d: ",x)
#define tc2(x)        printf("Case #%d: ",x)
#define tc3(x)        printf("Case %d:\n",x)
#define tc4(x)        printf("Case #%d:\n",x)

#define pr1(x)        cout<<x<<"\n"
#define pr2(x,y)      cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z)    cout<<x<<" "<<y<<" "<<z<<"\n"
#define pr4(w,x,y,z)  cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"
#define fast          ios::sync_with_stdio(0)
#define read          freopen("input.txt","r",stdin)
#define write         freopen("output.txt","w",stdout)
#define prflag1(flag) printf("%s\n",(flag)?"YES":"NO")
#define prflag2(flag) printf("%s\n",(flag)?"Yes":"No")
#define prflag3(flag) printf("%s\n",(flag)?"yes":"no")
/* defining macros */

using namespace std;

template <class T> inline T bigmod(T b, T p, T m)
{
    T ret;
    if(p==0) return 1;
    if(p&1)
    {
        ret=(bigmod(b,p/2,m)%m);
        return ((b%m)*ret*ret)%m;
    }
    else
    {
        ret=(bigmod(b,p/2,m)%m);
        return (ret*ret)%m;
    }
}
/* template functions */

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int>pii;
typedef pair<LL, LL>pll;
typedef vector<int>vi;
typedef vector<LL>vll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
/* type definition */

int dx4[]= {1,-1,0,0};
int dy4[]= {0,0,1,-1};
int dx6[]= {0,0,1,-1,0,0};
int dy6[]= {1,-1,0,0,0,0};
int dz6[]= {0,0,0,0,1,-1};
int dx8[]= {1,-1,0,0,-1,1,-1,1};
int dy8[]= {0,0,1,-1,1,1,-1,-1};
int dkx8[]= {-1,1,-1,1,-2,-2,2,2};
int dky8[]= {2,2,-2,-2,1,-1,1,-1};
/* direction array */

int tc=1;
const double eps=1e-9;
const double pi=acos(-1.0);
const long long int mx=1e5;
const long long int mod=1e9+7;
/* global declaration */

int level[mx+5];
vi edges[mx+5];
int n,m,maxi,k;

void dfs(int node, int l)
{
    int i,u;
    level[node]=l;
    if(l>maxi)
    {
        k=node;
        maxi=l;
    }
    for(i=0; i<edges[node].size(); i++)
    {
        u=edges[node][i];
        if(level[u]==-1) dfs(u,l+1);
    }
}

int main()
{
    int a,b;
    cin>>n>>m;
    while(m--)
    {
        scanf("%d %d",&a,&b);
        edges[a].pb(b);
        edges[b].pb(a);
    }
    maxi=k=0;
    setneg(level);
    dfs(1,0);
    maxi=0;
    setneg(level);
    dfs(k,0);
    pr1(level[k]);
    return 0;
}


/* -------------------------------- */
/* Name: MD. Khairul Basar          */
/* Institute: HSTU                  */
/* Dept: CSE                        */
/* Email: khairul.basar93@gmail.com */
/* -------------------------------- */

#include <bits/stdc++.h>
/* all header files included */

#define fs            first
#define sc            second
#define sp            printf(" ")
#define nl            printf("\n")
#define pb(a)         push_back(a)
#define mp(a,b)       make_pair(a,b)

#define setzero(a)    memset(a,0,sizeof(a))
#define setneg(a)     memset(a,-1,sizeof(a))
#define setinf(a)     memset(a,126,sizeof(a))

#define tc1(x)        printf("Case %d: ",x)
#define tc2(x)        printf("Case #%d: ",x)
#define tc3(x)        printf("Case %d:\n",x)
#define tc4(x)        printf("Case #%d:\n",x)

#define pr1(x)        cout<<x<<"\n"
#define pr2(x,y)      cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z)    cout<<x<<" "<<y<<" "<<z<<"\n"
#define pr4(w,x,y,z)  cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"
#define fast          ios::sync_with_stdio(0)
#define read          freopen("input.txt","r",stdin)
#define write         freopen("output.txt","w",stdout)
#define prflag1(flag) printf("%s\n",(flag)?"YES":"NO")
#define prflag2(flag) printf("%s\n",(flag)?"Yes":"No")
#define prflag3(flag) printf("%s\n",(flag)?"yes":"no")
/* defining macros */

using namespace std;

template <class T> inline T bigmod(T b, T p, T m)
{
    T ret;
    if(p==0) return 1;
    if(p&1)
    {
        ret=(bigmod(b,p/2,m)%m);
        return ((b%m)*ret*ret)%m;
    }
    else
    {
        ret=(bigmod(b,p/2,m)%m);
        return (ret*ret)%m;
    }
}
/* template functions */

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int>pii;
typedef pair<LL, LL>pll;
typedef vector<int>vi;
typedef vector<LL>vll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
/* type definition */

int dx4[]= {1,-1,0,0};
int dy4[]= {0,0,1,-1};
int dx6[]= {0,0,1,-1,0,0};
int dy6[]= {1,-1,0,0,0,0};
int dz6[]= {0,0,0,0,1,-1};
int dx8[]= {1,-1,0,0,-1,1,-1,1};
int dy8[]= {0,0,1,-1,1,1,-1,-1};
int dkx8[]= {-1,1,-1,1,-2,-2,2,2};
int dky8[]= {2,2,-2,-2,1,-1,1,-1};
/* direction array */

int tc=1;
const double eps=1e-9;
const double pi=acos(-1.0);
const long long int mx=1e5;
const long long int mod=1e9+7;
/* global declaration */

int level[mx+5];
vi edges[mx+5];
int n,m,maxi,k;

void dfs(int node, int l)
{
    int i,u;
    level[node]=l;
    if(l>maxi)
    {
        k=node;
        maxi=l;
    }
    for(i=0; i<edges[node].size(); i++)
    {
        u=edges[node][i];
        if(level[u]==0) dfs(u,l+1);
    }
}

int main()
{
    int a,b;
    cin>>n>>m;
    while(m--)
    {
        scanf("%d %d",&a,&b);
        edges[a].pb(b);
        edges[b].pb(a);
    }
    maxi=k=0;
    setzero(level);
    dfs(1,0);
    maxi=0;
    setzero(level);
    dfs(k,0);
    pr1(level[k]);
    return 0;
}


#include <bits/stdc++.h>

#define eps 1e-7
#define sq(x) ((x)*(x))
#define x1 kakaskakas
#define x2 jmjjmjjmjj
#define y1 spiderspid
#define y2 likolikoli
#define inf 0x3f3f3f3f
using namespace std;

template<class T> inline void smin(T &a, T b) {if(a>b) a=b;}
template<class T> inline void smax(T &a, T b) {if(a<b) a=b;}

#define pb push_back
#define NN 111111
int qf, qb, q[1111111];
int vst[NN], best[NN], res[NN];
vector<int> adj[NN], cadj[NN];

void make_tree(int u) {
	int i, v, deg;
	qf=qb=0;
	q[qb++]=u;
	vst[u]=1;
	while (qf<qb) {
		u=q[qf++], deg=cadj[u].size();
		for (i=0; i<deg; i++) {
			v=cadj[u][i];
			if (vst[v]) continue;
			vst[v]=1;
			adj[u].pb(v);
			q[qb++]=v;
		}
	}
}

int main() {

	int N, M, u, v, i, j, mid, k, deg, a[4];
	scanf("%d%d", &N, &M);
	for (i=0; i<M; i++) {
		scanf("%d%d", &u, &v);
		u--, v--;
		cadj[u].pb(v);
		cadj[v].pb(u);
	}
	make_tree(0);

	qf=qb=0;
	q[qb++]=0;
	while (qf<qb) {
		u=q[qf++], deg=adj[u].size();
		for (i=0; i<deg; i++) {
			q[qb++]=adj[u][i];
		}
	}

	for (i=qb-1; i>=0; i--) {
		u=q[i], deg=adj[u].size();
		if (deg==0) {
			best[u]=0, res[u]=0;
			continue;
		}

		best[u]=res[u]=mid=k=0;
		for (j=0; j<deg; j++) {
			v=adj[u][j];
			res[u]=max(res[u], res[v]);
			mid=max(mid, best[v]);
			a[k++]=res[v];
			if (k>2) {
				if (a[0]<a[1]) swap(a[0], a[1]);
				if (a[0]<a[2]) swap(a[0], a[2]);
				if (a[1]<a[2]) swap(a[1], a[2]);
				k=2;
			}
		}

		res[u]++;
		best[u]=max(res[u], best[u]);
		best[u]=max(mid, best[u]);
		if (k==1) continue;
		best[u]=max(best[u], a[0]+a[1]+2);
	}

	printf("%d\n", best[0]);

	return 0;
}


#include <bits/stdc++.h>

#define eps 1e-7
#define sq(x) ((x)*(x))
#define x1 kakaskakas
#define x2 jmjjmjjmjj
#define y1 spiderspid
#define y2 likolikoli
#define inf 0x3f3f3f3f
using namespace std;

template<class T> inline void smin(T &a, T b) {if(a>b) a=b;}
template<class T> inline void smax(T &a, T b) {if(a<b) a=b;}

#define pb push_back
#define NN 111111
int qf, qb, q[1111111];
int vst[NN], best[NN], res[NN];
vector<int> adj[NN], cadj[NN];

void make_tree(int u) {
	int i, v, deg;
	qf=qb=0;
	q[qb++]=u;
	vst[u]=1;
	while (qf<qb) {
		u=q[qf++], deg=cadj[u].size();
		for (i=0; i<deg; i++) {
			v=cadj[u][i];
			if (vst[v]) continue;
			vst[v]=1;
			adj[u].pb(v);
			q[qb++]=v;
		}
	}
}

int main() {
	int N, M, u, v, i, j, mid, k, deg, a[4];
	scanf("%d%d", &N, &M);
	for (i=0; i<M; i++) {
		scanf("%d%d", &u, &v);
		u--, v--;
		cadj[u].pb(v);
		cadj[v].pb(u);
	}
	make_tree(0);

	qf=qb=0;
	q[qb++]=0;
	while (qf<qb) {
		u=q[qf++], deg=adj[u].size();
		for (i=0; i<deg; i++) {
			q[qb++]=adj[u][i];
		}
	}

	for (i=qb-1; i>=0; i--) {
		u=q[i], deg=adj[u].size();
		if (deg==0) {
			best[u]=0, res[u]=0;
			continue;
		}

		best[u]=res[u]=mid=k=0;
		for (j=0; j<deg; j++) {
			v=adj[u][j];
			res[u]=max(res[u], res[v]);
			mid=max(mid, best[v]);
			a[k++]=res[v];
			if (k>2) {
				if (a[0]<a[1]) swap(a[0], a[1]);
				if (a[0]<a[2]) swap(a[0], a[2]);
				if (a[1]<a[2]) swap(a[1], a[2]);
				k=2;
			}
		}

		res[u]++;
		best[u]=max(res[u], best[u]);
		if (k==1) continue;
		best[u]=max(best[u], a[0]+a[1]+2);
	}

	printf("%d\n", best[0]);

	return 0;
}


//Copyright (c)2015 Liu chenrui
//This sourcecode is licensed under Devc++ 5.5.3
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<ctime>
#define eprintf(a,b) fprintf(stderr,a,b)
#define Op(_x) ((((_x)-1)^1)+1)
inline int max(int a,int b){return a>b?a:b;}
inline int min(int a,int b){return a<b?a:b;}
using std::cin;using std::cout;using std::endl;using std::sort;
int getint()
{
    int _b=0;char _c;
    for(_c=getchar();_c<'0'||_c>'9';_c=getchar());
    for(;_c>='0'&&_c<='9';_c=getchar())
    {
        _b=(_b<<3)+(_b<<1);
        _b+=_c-'0';
    }
    return _b;
}
struct Edge
{
    int to;
    int next;
    int len;
}edge[200010];
int first[100010],size;
int s,t;
int dl[100010];
int dis[100010],f[100010];
bool visit[100010];
int n,k;
void addedge(int x,int y)
{
    size++;
    edge[size].to=y;
    edge[size].next=first[x];
    first[x]=size;
    edge[size].len=1;
}
int M_id(int num)
{
    memset(dis,-1,sizeof dis);
    int head=0,tail=1;
    int ret=num,maxx=0;
    dl[1]=num;dis[num]=0;
    while(head!=tail)
    {
        head++;
        int now=dl[head];
        for(int u=first[now];u!=0;u=edge[u].next)
        {
            if(dis[edge[u].to]==-1)
            {
                dis[edge[u].to]=dis[now]+edge[u].len;
                tail++;
                dl[tail]=edge[u].to;
                if(dis[edge[u].to]>maxx)maxx=dis[edge[u].to],ret=edge[u].to;
            }
        }
    }
    return ret;
}
void dfs(int now)
{
    int max1=0,max2=0;
    visit[now]=true;
    for(int u=first[now];u!=0;u=edge[u].next)
    {
        if(!visit[edge[u].to])
        {
            dfs(edge[u].to);
            int v=dis[edge[u].to]+edge[u].len;
            dis[now]=max(dis[now],v);
            f[now]=max(f[now],f[edge[u].to]);
            if(v>max1){max2=max1;max1=v;}
            else if(v>max2)max2=v;
        }
    }
    f[now]=max(f[now],max1+max2);
}
int query()
{
    s=M_id(1);
    t=M_id(s);
    return dis[t];
}
int main()
{
    n=getint();k=getint();
    for(int i=1;i<=n-1;i++)
    {
        int x=getint();
        int y=getint();
        addedge(x,y);
        addedge(y,x);
    }
    int ret=query();
    printf("%d\n",ret);
}


#include <bits/stdc++.h>

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define form(i,a,b) for(int i=a;i<=b;i++)
#define lli long long
#define mp make_pair
#define pi pair<int,int>
#define pli pair<lli,lli>
#define pb push_back
#define x first
#define y second
#define sl(x) scanf("%I64d",&x)
#define pl(x) printf("%I64d\n",x)
#define sf(x) sort(x.begin(),x.end(),func)
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}

const double EPS = 1e-24;
const lli mod = 1000000007ll;
const lli mod1 = 1000000009ll;
const lli mod2 = 1100000009ll;
const double PI = 3.14159265359;
int INF = 2147483645;
lli INFINF = 9223372036854775807;

template <class T>T Max2(T a,T b){return a<b?b:a;}
template <class T>T Min2(T a,T b){return a<b?a:b;}
template <class T>T Max3(T a,T b,T c){return Max2(Max2(a,b),c);}
template <class T>T Min3(T a,T b,T c){return Min2(Min2(a,b),c);}
template <class T>T Max4(T a,T b,T c,T d){return Max2(Max2(a,b),Max2(c,d));}
template <class T>T Min4(T a,T b,T c,T d){return Min2(Min2(a,b),Max2(c,d));}

using namespace std;
lli bit_count(lli _x){lli _ret=0;while(_x){if(_x%2==1)_ret++;_x/=2;}return _ret;}
lli bit(lli _mask,lli _i){return (_mask&(1<<_i))==0?0:1;}
lli powermod(lli _a,lli _b,lli _m){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
lli add(lli a,lli b,lli m){lli x=a+b;while(x>=m)x-=m;return x;}
lli sub(lli a,lli b,lli m){lli x=a-b;while(x<0)x+=m;return x;}
lli mul(lli a,lli b,lli m){lli x=a*b;x%=m;return x;}

lli operator * (pi A,pi B) { return A.x*B.y-A.y*B.x; }
typedef vector< int > vi;
typedef vector< vi > vvi;
int j=0;
vvi gr(100001);
int v=0,d=0;
void dfs(int i, int dpt, vi &visit){
	visit[i]=1;
	if(dpt > d){
		//cout<<dpt<<endl;
		v = i;
		d = dpt;
	}
	vi::iterator it;
	for(it = gr[i].begin();it<gr[i].end();it++){
		if(!visit[*it])
			dfs(*it,dpt+1, visit);
	}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int n,m,a,b;
cin>>n>>m;
forn(i,m){
	cin>>a>>b;
	a--;
	b--;
	gr[a].pb(b);
	gr[b].pb(a);
}
 vi visit(100001,0);
 dfs(0,0,visit);
 d=0;
 vi vis(100001,0);
 dfs(v,0,vis);
 cout<<d;
}


#include <bits/stdc++.h>
#define mk make_pair
#define ps push_back
#define LL unsigned long long
using namespace std;
const int maxn=2e5+5;
vector<int> q[maxn];
int vis[maxn];
int dp[maxn][2];
int n,k;
int ans;
int sum[maxn];
void dfs(int u,int fa)
{
    int len=q[u].size();
    if(vis[u]) sum[u]=1;
    for(int i=0; i<len; i++)
    {
        int v=q[u][i];
        if(v==fa) continue;
        dfs(v,u);
        if(dp[v][0]+1>dp[u][0])
        {
            swap(dp[u][0],dp[u][1]);
            dp[u][0]=dp[v][0]+1;
        }
        else
            dp[u][1]=max(dp[u][1],dp[v][0]+1);
    }
    ans=max(dp[u][0]+dp[u][1],ans);
}
void dfs2(int u,int fa)
{
    int len=q[u].size();
    for(int i=0; i<len; i++)
    {
        int v=q[u][i];
        if(v==fa)continue;
        if(dp[v][0]+1==dp[u][0]){
            dp[v][1]=max(dp[v][1],dp[u][1]);
        }
        else{
           swap(dp[v][0],dp[v][1]);
           dp[v][0]=dp[u][0];
        }
        dfs2(v,u);
        ans=max(ans,dp[v][0]+dp[v][1]);
    }
}
int main()
{

    scanf("%d%d",&n,&k);
    for(int i=1; i<n; i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        q[u].push_back(v);
        q[v].push_back(u);
    }
    dfs(1,-1);
    dfs2(1,-1);
    printf("%d\n",ans);
//   printf("%lld\n",ans);
}


#include <iostream>
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <string>

using namespace std;

#define mp make_pair
#define pb push_back

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

const double PI = 3.14159265359;
const double EPS = 1e-9;
// const int INF = (2e9);
const ll INF = ((ll)1 << 62);

const ll P = 1e9 + 7;
int visited[100005];

struct node{
  ll val, dist;
  bool marked;
  node(){
    dist = 0;
    val = 0;
    marked = false;
  }

  // vector<edge> adj;
  vector<int> adj;
};

pii bfs(int curr, vector<node> &nodes){
  memset(visited, 0, sizeof(visited));
  visited[curr] = 1;
  queue< pii > q;
  q.push(mp(0, curr));

  pii last_out;
  while(!q.empty()){
    pii front = q.front();
    q.pop();
    last_out = front;
    int d = front.first;
    int v = front.second;

    for (int i = 0; i < nodes[v].adj.size(); ++i)
    {
      int next = nodes[v].adj[i];
      if(!visited[next]){
        visited[next] = 1;
        q.push(mp(d+1, next));
      }
    }
  }

  return last_out;
}

int main(){
  std::ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;

  vector<node> nodes(n+1);

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

  pii v = bfs(1, nodes);
  cout << bfs(v.second, nodes).first << endl;

  return 0;
}


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

int main()
{
	int n, m;
	cin >> n >> m;
	int a[2*m];
	int top[n+1];

	bool leaf[n+1];
	for(int i = 0; i < m; i++)
    {
        cin >> a[2*i] >> a[2*i+1];
    }
    for(int i = 1; i <= n ; i++)
        leaf[i]=true;

    queue<int> Q;
    int A = 0, B = 1, temp, i;
    Q.push(1);
    top[1] = 0;
    while(!Q.empty())
    {
        temp = Q.front();
        Q.pop();
        i = 0;
        while(i < 2*m)
        {
            if(a[i]==temp)
            {
                A = i;
                if(A%2==0) B=A+1;
                else B=A-1;
                Q.push(a[B]);
                leaf[a[A]] = false;
                top[a[B]] = a[A];
                a[A] = a[B] = 0;
                i++;
            }else
                i++;
        }
    }
    int m1[n+1];
	int m2[n+1];
	int dep[n+1];
    for(int i=1;i<=n;i++)
        m1[i] = m2[i] = dep[i] = 0;

    int counter;
    for(int i=1;i<=n;i++)
    {
        if(leaf[i])
        {
            counter = 1;
            temp = top[i];
            while(temp != 0)
            {
                if(counter > dep[temp])
                {
                    dep[temp] = counter;
                }else
                {
                    break;
                }
                temp = top[temp];
                counter++;
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        temp = top[i];
        if(dep[i] + 1  > m1[temp])
        {
            m2[temp] = m1[temp];
            m1[temp] = dep[i] + 1;
        }else if(dep[i] + 1 > m2[temp])
        {
            m2[temp] = dep[i] + 1;
        }
    }

    int max = 0;
    for(int i=1;i<=n;i++)
    {
        if( m1[i] + m2[i] > max ) max = m1[i] + m2[i];
        if( dep[i] > max ) max = dep[i];
    }
    cout << max << endl;
    return 0;

}


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

struct thing{
    int a;
    int b;
};

bool comp(thing X, thing Y)
{
    return X.a < Y.a;
}

void findthing(vector<thing> *ptr, int N, int temp, int&i, int&j)
{
    int k;
    if(ptr->at(0).a == temp)
    {
        i = 0;
        k = 0;
        while(ptr->at(k).a == temp) k++;
        j = k-1;
        return;
    }
    if(ptr->at(N-1).a == temp)
    {
        j = N-1;
        k = N-1;
        while(ptr->at(k).a == temp) k--;
        i = k+1;
        return;
    }
    int a, b, c;
    a = 0;
    b = N-1;
    c = (a+b)/2;
    while( ptr->at(c).a != temp )
    {
        if(ptr->at(c).a > temp) b = c;
        else a = c;
        c = (a+b)/2;
    }
    k = 0;
    while(ptr->at(c+k).a == temp)k++;
    j = c+k-1;
    k = 0;
    while(ptr->at(c+k).a == temp)k--;
    i = c+k+1;

}

int main()
{
	int n, m;
	cin >> n >> m;
	int top[n+1];
	bool leaf[n+1];
	bool done[n+1];
	int temp, t1, t2;
	vector<thing> edge(2*m);

	for(int i = 0; i < m; i++)
    {
        cin >> t1 >> t2;
        edge[2*i].a = edge[2*i+1].b = t1;
        edge[2*i].b = edge[2*i+1].a = t2;
    }
    sort(edge.begin(), edge.end(), comp);

    for(int i = 1; i <= n ; i++)
    {
        leaf[i] = true;
        done[i] = false;
    }

    queue<int> Q;
    int A = 0, B = 1;
    Q.push(1);
    top[1] = 0;
    while(!Q.empty())
    {
        temp = Q.front();
        done[temp] = true;
        Q.pop();
        findthing(&edge, 2*m, temp, t1, t2);
        for(int i=t1;i<=t2;i++)
        {
            if(done[edge[i].b]) continue;
            else
            {
                Q.push(edge[i].b);
                leaf[edge[i].a] = false;
                top[edge[i].b] = edge[i].a;
            }
        }
    }

    int m1[n+1];
	int m2[n+1];
	int dep[n+1];
    for(int i=1;i<=n;i++)
        m1[i] = m2[i] = dep[i] = 0;

    int counter;
    for(int i=1;i<=n;i++)
    {
        if(leaf[i])
        {
            counter = 1;
            temp = top[i];
            while(temp != 0)
            {
                if(counter > dep[temp])
                {
                    dep[temp] = counter;
                }else
                {
                    break;
                }
                temp = top[temp];
                counter++;
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        temp = top[i];
        if(dep[i] + 1  > m1[temp])
        {
            m2[temp] = m1[temp];
            m1[temp] = dep[i] + 1;
        }else if(dep[i] + 1 > m2[temp])
        {
            m2[temp] = dep[i] + 1;
        }
    }

    int max = 0;
    for(int i=1;i<=n;i++)
    {
        if( m1[i] + m2[i] > max ) max = m1[i] + m2[i];
        if( dep[i] > max ) max = dep[i];
    }
    cout << max << endl;
    return 0;

}


#include <bits/stdc++.h>

using namespace std;

int n , m;
vector <vector<int> > ver;
int ans=-10000;
//int dist[100009];
bool visit[100009];
int bfs(int v)
{
    memset(visit, 0, sizeof visit);
    queue <pair <int , int > > q;
    q.push(make_pair(v, 0));
    int l , u;
    visit[v]=0;
    while(!q.empty())
    {
        pair <int , int > p=q.front();
        l=p.second;
        u=p.first;
        q.pop();
        visit[u]=1;
        for(int i=0;i<ver[u].size();i++)
        {
            if(visit[ver[u][i]]==0)
            {
                q.push(make_pair(ver[u][i], l+1));
            }
        }
    }
    return u;
}

int bfs2(int v)
{
    memset(visit, 0, sizeof visit);
    queue <pair <int , int > > q;
    q.push(make_pair(v, 0));
    int l , u;
    visit[v]=0;
    while(!q.empty())
    {
        pair <int , int > p=q.front();
        l=p.second;
        u=p.first;
        q.pop();
        visit[u]=1;
        for(int i=0;i<ver[u].size();i++)
        {
            if(visit[ver[u][i]]==0)
            {
                q.push(make_pair(ver[u][i], l+1));
            }
        }
    }
    return l;
}

int main()
{
    scanf("%d %d", &n ,&m);
    int x, y;
    ver.resize(100009);
    for(int i=0;i<m;i++)
    {
        scanf("%d %d", &x, &y);
        ver[x].push_back(y);
        ver[y].push_back(x);
    }
        ans=bfs2(bfs(1));
      printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n , m;
vector <vector<int> > ver;
int ans=-10000;
//int dist[100009];
bool visit[100009];
void bfs(int v)
{
    memset(visit, 0, sizeof visit);
    queue <pair <int , int > > q;
    q.push(make_pair(v, 0));
    int l , u;
    visit[v]=0;
    while(!q.empty())
    {
       // cout<<u<<"       "<<v<<endl;
        pair <int , int > p=q.front();
        l=p.second;
        u=p.first;
        q.pop();
        visit[u]=1;
        ans=max(ans, l);
        for(int i=0;i<ver[u].size();i++)
        {
            if(visit[ver[u][i]]==0)
            {
                q.push(make_pair(ver[u][i], l+1));
            }
        }
    }
    return ;
}

int main()
{
    scanf("%d %d", &n ,&m);
    int x, y;
    ver.resize(100009);
    for(int i=0;i<m;i++)
    {
        scanf("%d %d", &x, &y);
        ver[x].push_back(y);
        ver[y].push_back(x);
    }
    //for(int i=1;i<=n;i++)
      //  dist[i]=10000000;
    for(int i=1;i<=n;i++)
    {
        bfs(i);
    }
   // for(int i=1;i<=n;i++)
      //  if(dist[i]>ans)
      //  ans=dist[i];
      printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
vector<int > v[maxn];
int f[maxn];
int du[maxn];
int n;
struct node{
    int cnt,deep;
};

int pos;
void work()
{
    queue<node > q;
    node c;
    c.cnt=1;
    c.deep=0;
    q.push(c);
    int ans=-1;
    pos=-1;
    while(!q.empty())
    {
        node d=q.front();
        q.pop();
        f[d.cnt]=1;
        if(ans<d.deep)
        {
            ans=d.deep;
            pos=d.cnt;
        }
        for(int i=0;i<v[d.cnt].size();i++)
        {
            if(f[v[d.cnt][i]]) continue;
            c.deep=d.deep+1;
            c.cnt=v[d.cnt][i];
            q.push(c);
        }
    }
}
void bfs()
{
    queue<node > q;
    node c;
    c.cnt=pos;
    c.deep=0;
    q.push(c);
    int ans=-1;
    while(!q.empty())
    {
        node d=q.front();
        q.pop();
        f[d.cnt]=1;
        if(ans<d.deep)
        {
            ans=d.deep;
            pos=d.cnt;
        }
        for(int i=0;i<v[d.cnt].size();i++)
        {
            if(f[v[d.cnt][i]]) continue;
            c.deep=d.deep+1;
            c.cnt=v[d.cnt][i];
            q.push(c);
        }
    }
    printf("%d\n",ans);
}
int main()
{
    int m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        v[a].push_back(b);
        v[b].push_back(a);
        du[b]++;
    }
    work();
    memset(f,0,sizeof(f));
    bfs();
    return 0;
}


//OM
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define  x first
#define  y second
#define  pb push_back
#define  mp make_pair
#define  PI (acos(-1.0))
#define  mem(a,b) memset(a,b,sizeof(a))
#define  Sort(x) sort(x.begin(),x.end())
#define  FOR(i, b, e) for(int i = b; i <= (int)(e); i++)
#define  FORR(i, b, e) for(int i = b; i >=(int)(e); i--)
#define  FORI(i, s) for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)
#define  pr(x) cout<<x<<"\n"
#define  prs(x) cout<<x<<" "
#define  pr2(x,y) cout<<x<<" "<<y<<"\n"
#define  pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define  ppr(a) cout<<a.x<<" "<<a.y<<"\n"

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  vector <int> vi;
typedef  vector <pii> vpii;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction

#define  EPS 1e-9
#define  MAX 100007
vi edge[1005];
int v[1005];
bool cycle=false;
int mx=-1,last;
void dfs(int u,int dis=0)
{
    v[u]=1;
    if(dis>mx){
        mx=dis;
        last=u;
    }
    FOR(i,0,(int)edge[u].size()-1)
    {
        int x=edge[u][i];
        if(!v[x])
            dfs(x,dis+1);
    }
}
int main()
{
    int T,n,m,a,b;
    scanf("%d",&n);
    scanf("%d",&m);
    FOR(i,1,m)
    {
        scanf("%d%d",&a,&b);
        edge[a].pb(b);
        edge[b].pb(a);

    }
    dfs(1);
    mem(v,0);
    mx=-1;
    dfs(last);
    printf("%d",mx);
    return 0;
}


//OM
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define  x first
#define  y second
#define  pb push_back
#define  mp make_pair
#define  PI (acos(-1.0))
#define  mem(a,b) memset(a,b,sizeof(a))
#define  Sort(x) sort(x.begin(),x.end())
#define  FOR(i, b, e) for(int i = b; i <= (int)(e); i++)
#define  FORR(i, b, e) for(int i = b; i >=(int)(e); i--)
#define  FORI(i, s) for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)
#define  pr(x) cout<<x<<"\n"
#define  prs(x) cout<<x<<" "
#define  pr2(x,y) cout<<x<<" "<<y<<"\n"
#define  pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define  ppr(a) cout<<a.x<<" "<<a.y<<"\n"

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  vector <int> vi;
typedef  vector <pii> vpii;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction

#define  EPS 1e-9
#define  MAX 100007
vi edge[100005];
int v[100005];
bool cycle=false;
int mx=-1,last;
void dfs(int u,int dis=0)
{
    v[u]=1;
    if(dis>mx){
        mx=dis;
        last=u;
    }
    FOR(i,0,(int)edge[u].size()-1)
    {
        int x=edge[u][i];
        if(!v[x])
            dfs(x,dis+1);
    }
}
int main()
{
    int T,n,m,a,b;
    scanf("%d",&n);
    scanf("%d",&m);
    FOR(i,1,m)
    {
        scanf("%d%d",&a,&b);
        edge[a].pb(b);
        edge[b].pb(a);

    }
    dfs(1);
    mem(v,0);
    mx=-1;
    dfs(last);
    printf("%d",mx);
    return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>

static void bfs(const std::vector< std::vector<long> > &g, long s,
			std::vector<long> &d)
{
	std::queue<long> q;

	d.assign(g.size(), -1);
	d[s] = 0;
	q.push(s);

	while (!q.empty()) {
		const long u = q.front(); q.pop();

		for (long i = 0; i != (long)g[u].size(); ++i) {
			const long v = g[u][i];

			if (d[v] != -1)
				continue;
			d[v] = d[u] + 1;
			q.push(v);
		}
	}
}

int main()
{
	std::ios_base::sync_with_stdio(false);
	long n, m;
	std::cin >> n >> m;

	std::vector< std::vector<long> > g(n);
	for (long i = 0; i != m; ++i) {
		long u, v;
		std::cin >> u >> v;

		g[u - 1].push_back(v - 1);
		g[v - 1].push_back(u - 1);
	}

	std::vector<long> dst(n);
	bfs(g, 0, dst);

	const long s = std::max_element(dst.begin(), dst.end()) - dst.begin();

	bfs(g, s, dst);
	std::cout << *std::max_element(dst.begin(), dst.end()) << "\n";

	return 0;
}


// Bismillahirrahmanir Rahim
//NAMOMIZARAHID
#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>

#define nl printf("\n")

#define Rep(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define repab(i,a,b) for(i=a;i<=b;i++)

#define fil freopen("input.txt","rt",stdin)

#define pf printf
#define sf scanf

typedef long long l;
typedef unsigned long long ul;

using namespace std;
/*
bool isprime(l n)
{
    for(l i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)return false;
    }
    return true;
}

bool prm[10000007];
l N= 10000000;

void sieve()
{
    prm[1]=1;
    for(l i=2;i<=sqrt(N);i++)
    {
        if(prm[i]==0)
        {
            for(l j=i+i;j<=N;j=j+i)prm[j]=1;
        }
    }
}

*/
/*
#define mod 1000000007
l bm(l b, l p)
{
    l namira;
    if(p==0)return 1;
    if(p%2==0)
    {
        namira=bm(b,p/2);
        return ((namira%mod)*(namira%mod))%mod;
    }
    else
    {
        return ((b%mod)*(bm(b,p-1)%mod))%mod;
    }
}

l modinverse(l a)
{

    return bm(a,mod-2);

}
*/
//#define mx 200010
//SEGMENT TREE
/*
l tree1[mx*3],nami[1000010],nam[1000010],check[1000010];
void init(l node,l b,l e)
{
    if(b==e)
    {
        tree1[node]=1;
        return;
    }
    l Left=node*2;
    l Right=node*2+1;
    l mid=(b+e)/2;
    init(Left,b,mid);
    init(Right,mid+1,e);
    tree1[node]=tree1[Left]+tree1[Right];

}

l query(l node,l b,l e,l i)
{
    if(nam[b]>i) return 0;
    if(nam[e]<=i)
    {
        return tree1[node];
    }
    l Left=node*2;
    l Right=node*2+1;
    l mid=(b+e)/2;
    l p1=query(Left,b,mid,i);
    l p2=query(Right,mid+1,e,i);
    return p1+p2;

}
void update(l node,l b,l e,l i,l newvalue)
{
    if (i > e || i < b) return;
    if (b >= i && e <= i)
    {
        tree1[node]=newvalue;
        return;
    }
    l Left=node*2;
    l Right=node*2+1;
    l mid=(b+e)/2;
    update(Left,b,mid,i,newvalue);
    update(Right,mid+1,e,i,newvalue);
    tree1[node]=tree1[Left]+tree1[Right];
}

//SEGMENT TREE END
/*
l NcR[200010][2];

l ncr(int n,int r)
{
    if(r==0)return 1;
    if(r==1)return n;
    if(n==r)return 1;
    if(NcR[n][r]!=0)
    {
        return NcR[n][r];
    }
    else
    {
        NcR[n][r]=ncr(n-1,r)+ncr(n-1,r-1);
        return NcR[n][r];
    }
}
*/
//bool L[100010],R[100010];
// Here starts main function :-)
/*char s[110][110];

bool ok(l i,l S,l e)
{
    l j;
    for(j=S+1;j<=e;j++)
    {
        if(s[j][i]<s[j-1][i])
        {
            return false;
        }
    }
    return true;
}

l gcd(l a,l b)
{
     if(b == 0)
     {
         return a;
     }
     else
       return gcd(b, a % b);
}*/
/*
int level[100010],r,c;
bool C[100010],vis[100010];
vector<int>V[100010],L[100010],R1,R2,R;
void bfs(l s)
{
	//memset(vis,0,sizeof vis);
	vis[s]=1;
	L[0].push_back(s);
	queue<l>q; //A queue containing STL pairs
	q.push(s);
	while(!q.empty())
	{
        int u=q.front();
        for(l i=0;i<V[u].size();i++)
        {
            int v=V[u][i];
            if(!vis[v])
            {
                vis[v]=1;
                level[v]=level[u]+1;
                if(level[v]>c)c=level[v];
                L[level[v]].push_back(v);
                q.push(v);
            }
            else
            {
                if(level[u]==level[v])
                {
                    r=0;
                }
            }
        }
        q.pop();
	}
}
*/

//l a[10010],n;

/*
l F(l p,l Max,l Min)
{
    if(p==n)return 0;
    if(a[p-1]<Min)Min=a[p-1];
    l max1=F(p+1,Max,Min);
    Max=max(Max,a[p]-Min);
    return Max=max(Max,max1);
}
*/

//#define valid(nx,ny,r,c) nx>=1&&nx<=r &&ny>=1&&ny<=c
//l fx[]={0,0,-1,1};
//l fy[]={-1,1,0,0};
//vector<l>outdeg[100010],indeg[100010];

/*

    for(i=0;i<n;i++)
    {
        sf("%I64d",&a[i]);
    }

*/
//sf("%I64d",&n);
//%I64d
#define INF 0x7f7f7f
#define MAX 1000000001
#define MIN -1000000001
struct info
{
    l x,y;
    info() {};
    info(l _x, l _y) {x = _x; y = _y;};

    bool operator < (const info &p) const
    {
		if(x == p.x) return y > p.y;
		else
			return x > p.x;
    }
};

l vis[100010],dis[100010],d,node;
vector<l>V[100010],R;

void F(l s)
{
    vis[s]=1;
    for(l i=0;i<V[s].size();i++)
    {
        l v=V[s][i];
        if(vis[v]==0)
        {
            vis[v]=1;
            dis[v]=dis[s]+1;
            if(dis[v]>d)
            {
                d=dis[v];
                node=v;
            }
            F(v);
        }
    }
}
//vector<l>V[10010];

int main()
{
	//fil;
	l i,x,n,m,u,v;
	cin>>n>>m;
	for(l i=0;i<m;i++)
	{
		cin>>u>>v;
		if(i==0)x=u;
		V[u].push_back(v);
		V[v].push_back(u);
	}
	dis[x]=0;
	d=0;
	F(x);
	memset(vis,0,sizeof(vis));
	memset(dis,0,sizeof(dis));
	dis[node]=0;
	d=0;
    dis[node]=0;
    F(node);
    pf("%I64d\n",d);
	return 0;
}


// Bismillahirrahmanir Rahim
//NAMOMIZARAHID
#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>

#define nl printf("\n")

#define Rep(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define repab(i,a,b) for(i=a;i<=b;i++)

#define fil freopen("input.txt","rt",stdin)

#define pf printf
#define sf scanf

typedef long long l;
typedef unsigned long long ul;

using namespace std;
/*
bool isprime(l n)
{
    for(l i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)return false;
    }
    return true;
}

bool prm[10000007];
l N= 10000000;

void sieve()
{
    prm[1]=1;
    for(l i=2;i<=sqrt(N);i++)
    {
        if(prm[i]==0)
        {
            for(l j=i+i;j<=N;j=j+i)prm[j]=1;
        }
    }
}

*/
/*
#define mod 1000000007
l bm(l b, l p)
{
    l namira;
    if(p==0)return 1;
    if(p%2==0)
    {
        namira=bm(b,p/2);
        return ((namira%mod)*(namira%mod))%mod;
    }
    else
    {
        return ((b%mod)*(bm(b,p-1)%mod))%mod;
    }
}

l modinverse(l a)
{

    return bm(a,mod-2);

}
*/
//#define mx 200010
//SEGMENT TREE
/*
l tree1[mx*3],nami[1000010],nam[1000010],check[1000010];
void init(l node,l b,l e)
{
    if(b==e)
    {
        tree1[node]=1;
        return;
    }
    l Left=node*2;
    l Right=node*2+1;
    l mid=(b+e)/2;
    init(Left,b,mid);
    init(Right,mid+1,e);
    tree1[node]=tree1[Left]+tree1[Right];

}

l query(l node,l b,l e,l i)
{
    if(nam[b]>i) return 0;
    if(nam[e]<=i)
    {
        return tree1[node];
    }
    l Left=node*2;
    l Right=node*2+1;
    l mid=(b+e)/2;
    l p1=query(Left,b,mid,i);
    l p2=query(Right,mid+1,e,i);
    return p1+p2;

}
void update(l node,l b,l e,l i,l newvalue)
{
    if (i > e || i < b) return;
    if (b >= i && e <= i)
    {
        tree1[node]=newvalue;
        return;
    }
    l Left=node*2;
    l Right=node*2+1;
    l mid=(b+e)/2;
    update(Left,b,mid,i,newvalue);
    update(Right,mid+1,e,i,newvalue);
    tree1[node]=tree1[Left]+tree1[Right];
}

//SEGMENT TREE END
/*
l NcR[200010][2];

l ncr(int n,int r)
{
    if(r==0)return 1;
    if(r==1)return n;
    if(n==r)return 1;
    if(NcR[n][r]!=0)
    {
        return NcR[n][r];
    }
    else
    {
        NcR[n][r]=ncr(n-1,r)+ncr(n-1,r-1);
        return NcR[n][r];
    }
}
*/
//bool L[100010],R[100010];
// Here starts main function :-)
/*char s[110][110];

bool ok(l i,l S,l e)
{
    l j;
    for(j=S+1;j<=e;j++)
    {
        if(s[j][i]<s[j-1][i])
        {
            return false;
        }
    }
    return true;
}

l gcd(l a,l b)
{
     if(b == 0)
     {
         return a;
     }
     else
       return gcd(b, a % b);
}*/
/*
int level[100010],r,c;
bool C[100010],vis[100010];
vector<int>V[100010],L[100010],R1,R2,R;
void bfs(l s)
{
	//memset(vis,0,sizeof vis);
	vis[s]=1;
	L[0].push_back(s);
	queue<l>q; //A queue containing STL pairs
	q.push(s);
	while(!q.empty())
	{
        int u=q.front();
        for(l i=0;i<V[u].size();i++)
        {
            int v=V[u][i];
            if(!vis[v])
            {
                vis[v]=1;
                level[v]=level[u]+1;
                if(level[v]>c)c=level[v];
                L[level[v]].push_back(v);
                q.push(v);
            }
            else
            {
                if(level[u]==level[v])
                {
                    r=0;
                }
            }
        }
        q.pop();
	}
}
*/

//l a[10010],n;

/*
l F(l p,l Max,l Min)
{
    if(p==n)return 0;
    if(a[p-1]<Min)Min=a[p-1];
    l max1=F(p+1,Max,Min);
    Max=max(Max,a[p]-Min);
    return Max=max(Max,max1);
}
*/

//#define valid(nx,ny,r,c) nx>=1&&nx<=r &&ny>=1&&ny<=c
//l fx[]={0,0,-1,1};
//l fy[]={-1,1,0,0};
//vector<l>outdeg[100010],indeg[100010];

/*

    for(i=0;i<n;i++)
    {
        sf("%I64d",&a[i]);
    }

*/
//sf("%I64d",&n);
//%I64d
#define INF 0x7f7f7f
#define MAX 1000000001
#define MIN -1000000001
struct info
{
    l x,y;
    info() {};
    info(l _x, l _y) {x = _x; y = _y;};

    bool operator < (const info &p) const
    {
		if(x == p.x) return y > p.y;
		else
			return x > p.x;
    }
};

l vis[100010],dis[100010],d;
vector<l>V[100010],R;

void F(l s)
{
    vis[s]=1;
    for(l i=0;i<V[s].size();i++)
    {
        l v=V[s][i];
        if(vis[v]==0)
        {
            vis[v]=1;
            dis[v]=dis[s]+1;
            if(dis[v]>d)d=dis[v];
            F(v);
        }
    }
}
//vector<l>V[10010];

int main()
{
	//fil;
	l i,x,n,m,u,v,r;
	cin>>n>>m;
	for(l i=0;i<m;i++)
	{
		cin>>u>>v;
		if(i==0)x=u;
		V[u].push_back(v);
		V[v].push_back(u);
	}
	dis[x]=0;
	for(l i=0;i<V[x].size();i++)
    {
        d=0;
        memset(vis,0,sizeof(vis));
        memset(dis,0,sizeof(dis));
        vis[x]=1;
        dis[V[x][i]]=0;
        vis[V[x][i]]=1;
        F(V[x][i]);
        R.push_back(d);

    }
    sort(R.begin(),R.end());
    d=R.size();
    if(d==1)
    {
        r=R[0]+1;
    }
    else
    {
        r=R[d-1]+R[d-2]+2;
    }
    pf("%I64d\n",r);
	return 0;
}


#include<iostream>
#include<queue>
#include<vector>

using namespace std;

int n, u, p, Max=0;
const int maxn=1e5+10;
int a[maxn];
queue <int> ver;
vector <int> ras[maxn];

int out()
{
	int mam=0;
	for(int i=1 ; i<=n ; i++)
		if( a[i]>mam )
		{
			mam = a[i];
			p = i;
		}
	if( Max>mam )
		cout<< Max;
	else
		cout<< mam;
}

int write()
{
	for(int i=1 ; i<=n ; i++)
		if( a[i]>Max )
		{
			Max = a[i];
			p = i;
		}
	for(int i=1 ; i<=n ; i++)
		a[i] = 0;
	a[p] = 0;
	ver.push( p );
	while( ver.size() > 0 )
	{
		for(int i=0 ; ras[ ver.front() ].size() > i ; i++)
		{
			if( a[ ras[ ver.front() ][i] ]==0 )
			{
				ver.push( ras[ ver.front() ][i] );
				a[ ras[ ver.front() ][i] ] = a[ ver.front() ] + 1;
			}
		}
		ver.pop();
	}
	out();
}

int bfs()
{
	for(int i=1 ; i<=n ; i++)
		if( ras[i].size() == 1 )
			p = i;
	a[p] = 0;
	ver.push( p );
	while( ver.size() > 0 )
	{
		for(int i=0 ; ras[ ver.front() ].size() > i ; i++)
		{
			if( a[ ras[ ver.front() ][i] ]==0 )
			{
				ver.push( ras[ ver.front() ][i] );
				a[ ras[ ver.front() ][i] ] = a[ ver.front() ] + 1;
			}
		}
		ver.pop();
	}
}

int main()
{
	cin>> n>> u;
	for(int i=1 ; i<n ; i++)
	{
		int x, y;
		cin>> x>> y;
		ras[ x ].push_back( y );
		ras[ y ].push_back( x );
	}
	bfs();
	write();
}


#include<iostream>
#include<queue>
#include<vector>

using namespace std;

int n, u, p, Max=0;
const int maxn=1e5+10;
int a[maxn];
queue <int> ver;
vector <int> ras[maxn];

int out()
{
	int mam=0;
	for(int i=1 ; i<=n ; i++)
		if( a[i]>mam )
		{
			mam = a[i];
			p = i;
		}
	if( Max>=mam )
		cout<< Max-1;
	else
		cout<< mam-1;
}

int write()
{
	for(int i=1 ; i<=n ; i++)
		if( a[i]>Max )
		{
			Max = a[i];
			p = i;
		}
	for(int i=1 ; i<=n ; i++)
		a[i] = 0;
	a[p] = 1;
	ver.push( p );
	while( ver.size() > 0 )
	{
		for(int i=0 ; ras[ ver.front() ].size() > i ; i++)
			if( a[ ras[ ver.front() ][i] ]==0 )
			{
				ver.push( ras[ ver.front() ][i] );
				a[ ras[ ver.front() ][i] ] = a[ ver.front() ] + 1;
			}
		ver.pop();
	}
	out();
}

int bfs()
{
	for(int i=1 ; i<=n ; i++)
		if( ras[i].size() == 1 )
			p = i;
	a[p] = 0;
	ver.push( p );
	while( ver.size() > 0 )
	{
		for(int i=0 ; ras[ ver.front() ].size() > i ; i++)
		{
			if( a[ ras[ ver.front() ][i] ]==0 )
			{
				ver.push( ras[ ver.front() ][i] );
				a[ ras[ ver.front() ][i] ] = a[ ver.front() ] + 1;
			}
		}
		ver.pop();
	}
}

int main()
{
	cin>> n>> u;
	for(int i=1 ; i<n ; i++)
	{
		int x, y;
		cin>> x>> y;
		ras[ x ].push_back( y );
		ras[ y ].push_back( x );
	}
	bfs();
	write();
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		long long int l, r, a, b, s1, s2;

		cin>>l>>r;

		if((r-l+1)%2 ==0)
		{
			if(l%2 == 0)
				cout<<-(r-l+1)/2<<endl;
			else
				cout<<(r-l+1)/2<<endl;
		}
		else
		{
			if(l%2 == 0)
				cout<<(long long int)-(r-l+1)/2+(r)<<endl;
			else
				cout<<(long long int)(r-l+1)/2+(r*(-1))<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		long long int l, r, a, b, s1, s2;

		cin>>l>>r;

		if((r-l+1)%2 ==0)
		{
			if(l%2 == 0)
				cout<<-(r-l+1)/2<<endl;
			else
				cout<<(r-l+1)/2<<endl;
		}
		else
		{
			if(l%2 == 0)
				cout<<(long long int)-(r-l+1)/2+(r)<<endl;
			else
				cout<<(long long int)(r-l+1)/2+(r*-1)<<endl;
		}
	}
}#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		long long int l, r, a, b, s1, s2;

		cin>>l>>r;

		if((r-l+1)%2 ==0)
		{
			if(l%2 == 0)
				cout<<-(r-l+1)/2<<endl;
			else
				cout<<(r-l+1)/2<<endl;
		}
		else
		{
			if(l%2 == 0)
				cout<<(long long int)-(r-l+1)/2+(r)<<endl;
			else
				cout<<(long long int)(r-l+1)/2+(r*-1)<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		long long int l, r, sum=0;

		cin>>l>>r;

		for(int i=l; i<=r; i++)
		{
			sum = sum + (i * pow(-1, i));
		}

		cout<<sum<<endl;
	}
}


#include<bits/stdc++.h>
#define lli long long int
using namespace std;

int main()
{
	int qu;
	cin>>qu;
	lli l,r;
	while(qu!=0)
	{
		lli ans=0;
		cin>>l>>r;
		ios_base::sync_with_stdio(false);
   		cin.tie(NULL);
		for(lli i=l;i<=r;i++)
		{
			if(i%2==0)
			{
				ans=ans+i;
			}
			else
			{
				ans=ans-i;
			}
		}
		cout<<ans<<endl;
		qu--;
	}
	return 0;
}


#include<bits/stdc++.h>
#define lli long long int
using namespace std;

int main()
{
	int qu;
	cin>>qu;
	int q[1001];
	lli l,r;
	while(qu!=0)
	{
		lli ans=0;
		cin>>l>>r;
		ios_base::sync_with_stdio(false);
   		cin.tie(NULL);
		for(lli i=l;i<=r;i++)
		{
			if(i%2==0)
			{
				ans=ans+i;
			}
			else
			{
				ans=ans-i;
			}
		}
		cout<<ans<<"\n";
		qu--;
	}
	return 0;
}


#include<bits/stdc++.h>
#define lli long long int
using namespace std;

int main()
{
	int qu;
	cin>>qu;
	lli l,r;
	while(qu!=0)
	{
		lli ans=0;
		cin>>l>>r;
		for(lli i=l;i<=r;i++)
		{
			if(i%2==0)
			{
				ans=ans+i;
			}
			else
			{
				ans=ans-i;
			}
		}
		cout<<ans<<endl;
		qu--;
	}
	return 0;
}


#include<bits/stdc++.h>
#define lli long long int
using namespace std;

lli sod(lli n)
{
	lli s;
	if(n%2!=0)
	{
		s=-(((n+1)/2)*((n+1)/2) -  (  ((n-1)/2) * (((n-1)/2)+1)    ));
	}
	else
	{
		s=-( (n/2)*(n/2) -(n/2)*((n/2)+1) );
	}
	return s;
}

int main()
{
	int qu;
	cin>>qu;
	lli l,r;
	while(qu!=0)
	{
		lli ans=0;
		cin>>l>>r;
		ans=sod(r)-sod(l-1);
		cout<<ans<<endl;
		qu--;
	}
	return 0;
}


#include<bits/stdc++.h>
#define lli long long int
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
   	cin.tie(NULL);
	int qu;
	cin>>qu;
	lli l,r;
	while(qu!=0)
	{
		lli ans=0;
		cin>>l>>r;
		for(lli i=l;i<=r;i++)
		{
			if(i%2==0)
			{
				ans=ans+i;
			}
			else
			{
				ans=ans-i;
			}
		}
		cout<<ans<<endl;
		qu--;
	}
	return 0;
}


#include <iostream>

using namespace std;

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

    short q;

    cin>>q;

    int l,r;
    int answer[100]={};
    short i=0;
    while(q)
        {
        cin>>l>>r;
        if(l%2==1)
            {
            if(r%2==1) answer[i]=(r-l)/-2-l;
            else answer[i]=(r-l+1)/2;
            }
        else
            {
            if(r%2==0) answer[i]=(r-l)/2+l;
            else answer[i]=-(r-l+1)/2;
            }
        ++i;
        --q;
        }
        for(int j=0;j<i;++j)
            {
            cout<<answer[j]<<"\n";
            }
}


#include <bits/stdc++.h>

using namespace std;

int main(){

    short q;

    cin>>q;

    int l,r;
    long long answer[100]={};
    int l_pos_odd=-1,l_pos_even=-1,r_pos_odd=-1,r_pos_even=-1;
    short i=0;
    while(q)
        {
        cin>>l>>r;
        if(l%2==1)
            {
            l_pos_odd=l;
            l_pos_even=l+1;
            }
        else
            {
            l_pos_odd=l+1;
            l_pos_even=l;
            };
        if(r%2==1)
            {
            r_pos_odd=r;
            r_pos_even=r-1;
            }
        else
            {
            r_pos_odd=r-1;
            r_pos_even=r;
            };
            if(r_pos_odd>l_pos_odd) answer[i]+=(-1)*(r_pos_odd+l_pos_odd)/2*((r_pos_odd-l_pos_odd)/2+1);
        if(r_pos_even>l_pos_even) answer[i]+=(r_pos_even+l_pos_even)*((r_pos_even+l_pos_even)/2-1)/2;
        if(r_pos_even==l_pos_even) answer[i]+=r_pos_even;
        if(r_pos_odd==l_pos_odd) answer[i]+=-r_pos_odd;
        ++i;
        --q;
        }
        for(int j=0;j<i;++j)
            {
            cout<<answer[j]<<"\n";
            }
}


#include <bits/stdc++.h>

using namespace std;

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

    short q;

    cin>>q;

    int l,r;
    long long answer[100]={};
    int l_pos_odd=-1,l_pos_even=-1,r_pos_odd=-1,r_pos_even=-1;
    short i=0;
    while(q)
        {
        cin>>l>>r;
        if(l%2==1)
            {
            l_pos_odd=l;
            l_pos_even=l+1;
            }
        else
            {
            l_pos_odd=l+1;
            l_pos_even=l;
            };
        if(r%2==1)
            {
            r_pos_odd=r;
            r_pos_even=r-1;
            }
        else
            {
            r_pos_odd=r-1;
            r_pos_even=r;
            };
            long long o_1=r_pos_odd+l_pos_odd;
            long long o_2=r_pos_odd-l_pos_odd;
        if(r_pos_odd>l_pos_odd){
                answer[i]+=(-1)*(o_1)/2;
        answer[i]*=((o_2)/2+1);
        }
        o_1=r_pos_even+l_pos_even;
        o_2=r_pos_even-l_pos_even;
        long long check=0;
        if(r_pos_even>l_pos_even) {
                check+=(o_1)/2;
          check*=((o_2)/2+1);}
          answer[i]+=check;
        if(r_pos_even==l_pos_even) answer[i]+=r_pos_even;
        if(r_pos_odd==l_pos_odd) answer[i]+=-r_pos_odd;
        ++i;
        --q;
        }
        for(int j=0;j<i;++j)
            {
            cout<<answer[j]<<"\n";
            }
}


#include <iostream>

using namespace std;

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

    short q;

    cin>>q;

    int l,r;
    int answer[100]={};
    short i=0;
    while(q)
        {
        cin>>l>>r;
        if(l&1)
            {
            if(r&1) answer[i]=(r-l)/-2-l;
            else answer[i]=(r-l+1)/2;
            }
        else
            {
            if(r&1==0) answer[i]=(r-l)/2+l;
            else answer[i]=-(r-l+1)/2;
            }
        ++i;
        --q;
        }
        for(int j=0;j<i;++j)
            {
            cout<<answer[j]<<"\n";
            }
}


#include <iostream>

using namespace std;

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

    short q;

    cin>>q;

    int l,r;
    long long answer[100]={};
    int l_pos_odd,l_pos_even,r_pos_odd,r_pos_even;
    short i=0;
    long long o_2,o_1,check;
    while(q)
        {
        cin>>l>>r;
        if(l%2==1)
            {
            l_pos_odd=l;
            l_pos_even=l+1;
            }
        else
            {
            l_pos_odd=l+1;
            l_pos_even=l;
            };
        if(r%2==1)
            {
            r_pos_odd=r;
            r_pos_even=r-1;
            }
        else
            {
            r_pos_odd=r-1;
            r_pos_even=r;
            };
             o_1=r_pos_odd+l_pos_odd;
             o_2=r_pos_odd-l_pos_odd;
        if(r_pos_odd>l_pos_odd){
                answer[i]-=o_1/2;
        answer[i]*=(o_2/2+1);
        }
        o_1=r_pos_even+l_pos_even;
        o_2=r_pos_even-l_pos_even;
        check=0;
        if(r_pos_even>l_pos_even) {
                check+=o_1/2;
          check*=(o_2/2+1);}
          answer[i]+=check;
        if(r_pos_even==l_pos_even) answer[i]+=r_pos_even;
        if(r_pos_odd==l_pos_odd) answer[i]-=r_pos_odd;
        ++i;
        --q;
        }
        for(int j=0;j<i;++j)
            {
            cout<<answer[j]<<"\n";
            }
}


#include <iostream>

using namespace std;

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

    short q;

    cin>>q;

    int l,r;
    long long answer[100]={};
    short i=0;
    while(q)
        {
        cin>>l>>r;
        if(l%2==1)
            {
            if(r%2==1) answer[i]=(r-l)/-2-l;
            else answer[i]=(r-l+1)/2;
            }
        else
            {
            if(r%2==0) answer[i]=(r-l)/2+l;
            else answer[i]=-(r-l+1)/2;
            }
        ++i;
        --q;
        }
        for(int j=0;j<i;++j)
            {
            cout<<answer[j]<<"\n";
            }
}


й#include <iostream>

using namespace std;

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

    short q;

    cin>>q;

    int l,r;
    int answer[100]={};
    short i=0;
    while(q)
        {
        cin>>l>>r;
        if(l%2==1)
            {
            if(r%2==1) answer[i]=(r-l)/-2-l;
            else answer[i]=(r-l+1)/2;
            }
        else
            {
            if(r%2==0) answer[i]=(r-l)/2+l;
            else answer[i]=-(r-l+1)/2;
            }
        ++i;
        --q;
        }
        for(int j=0;j<i;++j)
            {
            cout<<answer[j]<<"\n";
            }
}


#include <bits/stdc++.h>

using namespace std;

int main(){

    short q;

    cin>>q;

    int l,r;
    long long answer[100]={};
    int l_pos_odd=-1,l_pos_even=-1,r_pos_odd=-1,r_pos_even=-1;
    short i=0;
    while(q)
        {
        cin>>l>>r;
        if(l%2==1)
            {
            l_pos_odd=l;
            l_pos_even=l+1;
            }
        else
            {
            l_pos_odd=l+1;
            l_pos_even=l;
            };
        if(r%2==1)
            {
            r_pos_odd=r;
            r_pos_even=r-1;
            }
        else
            {
            r_pos_odd=r-1;
            r_pos_even=r;
            };
            cout<<"\n\n"<<l_pos_odd<<r_pos_odd<<l_pos_even<<r_pos_even<<"\n\n";
        if(r_pos_odd>l_pos_odd) answer[i]+=(-1)*(r_pos_odd+l_pos_odd)/2*((r_pos_odd-l_pos_odd)/2+1);
        if(r_pos_even>l_pos_even) answer[i]+=(r_pos_even+l_pos_even)*((r_pos_even+l_pos_even)/2-1)/2;
        if(r_pos_even==l_pos_even) answer[i]+=r_pos_even;
        if(r_pos_odd==l_pos_odd) answer[i]+=-r_pos_odd;
        ++i;
        --q;
        }
        for(int j=0;j<i;++j)
            {
            cout<<answer[j]<<"\n";
            }
}


#include <bits/stdc++.h>

using namespace std;

int main(){

    short q;

    cin>>q;

    int l,r;
    long long answer[100]={};
    int l_pos_odd=-1,l_pos_even=-1,r_pos_odd=-1,r_pos_even=-1;
    short i=0;
    while(q)
        {
        cin>>l>>r;
        if(l%2==1)
            {
            l_pos_odd=l;
            l_pos_even=l+1;
            }
        else
            {
            l_pos_odd=l+1;
            l_pos_even=l;
            };
        if(r%2==1)
            {
            r_pos_odd=r;
            r_pos_even=r-1;
            }
        else
            {
            r_pos_odd=r-1;
            r_pos_even=r;
            };
            long long o_1=r_pos_odd+l_pos_odd;
            long long o_2=r_pos_odd-l_pos_odd;
        if(r_pos_odd>l_pos_odd) answer[i]+=(-1)*(o_1)/2*((o_2)/2+1);
        o_1=r_pos_even+l_pos_even;
        o_2=r_pos_even+l_pos_even;
        if(r_pos_even>l_pos_even) answer[i]+=(o_1)/2*((o_2)/2-1);
        if(r_pos_even==l_pos_even) answer[i]+=r_pos_even;
        if(r_pos_odd==l_pos_odd) answer[i]+=-r_pos_odd;
        ++i;
        --q;
        }
        for(int j=0;j<i;++j)
            {
            cout<<answer[j]<<"\n";
            }
}


#include <bits/stdc++.h>

using namespace std;

int main(){

    short q;

    cin>>q;

    int l,r;
    long long answer[100]={};
    int l_pos_odd=-1,l_pos_even=-1,r_pos_odd=-1,r_pos_even=-1;
    short i=0;
    while(q)
        {
        cin>>l>>r;
        if(l%2==1)
            {
            l_pos_odd=l;
            l_pos_even=l+1;
            }
        else
            {
            l_pos_odd=l+1;
            l_pos_even=l;
            };
        if(r%2==1)
            {
            r_pos_odd=r;
            r_pos_even=r-1;
            }
        else
            {
            r_pos_odd=r-1;
            r_pos_even=r;
            };
            long long o_1=r_pos_odd+l_pos_odd;
            long long o_2=r_pos_odd-l_pos_odd;
        if(r_pos_odd>l_pos_odd){
                answer[i]+=(-1)*(o_1)/2;
        answer[i]*=((o_2)/2+1);
        }
        o_1=r_pos_even+l_pos_even;
        o_2=r_pos_even+l_pos_even;
        if(r_pos_even>l_pos_even) {
                answer[i]+=(o_1)/2;
          answer[i]*=((o_2)/2-1);}
        if(r_pos_even==l_pos_even) answer[i]+=r_pos_even;
        if(r_pos_odd==l_pos_odd) answer[i]+=-r_pos_odd;
        ++i;
        --q;
        }
        for(int j=0;j<i;++j)
            {
            cout<<answer[j]<<"\n";
            }
}


#include <bits/stdc++.h>

using namespace std;

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

    short q;

    cin>>q;

    int l,r;
    long long answer[100]={};
    int l_pos_odd,l_pos_even,r_pos_odd,r_pos_even;
    short i=0;
    while(q)
        {
        cin>>l>>r;
        if(l%2==1)
            {
            l_pos_odd=l;
            l_pos_even=l+1;
            }
        else
            {
            l_pos_odd=l+1;
            l_pos_even=l;
            };
        if(r%2==1)
            {
            r_pos_odd=r;
            r_pos_even=r-1;
            }
        else
            {
            r_pos_odd=r-1;
            r_pos_even=r;
            };
            long long o_1=r_pos_odd+l_pos_odd;
            long long o_2=r_pos_odd-l_pos_odd;
        if(r_pos_odd>l_pos_odd){
                answer[i]-=o_1/2;
        answer[i]*=(o_2/2+1);
        }
        o_1=r_pos_even+l_pos_even;
        o_2=r_pos_even-l_pos_even;
        long long check=0;
        if(r_pos_even>l_pos_even) {
                check+=o_1/2;
          check*=(o_2/2+1);}
          answer[i]+=check;
        if(r_pos_even==l_pos_even) answer[i]+=r_pos_even;
        if(r_pos_odd==l_pos_odd) answer[i]-=r_pos_odd;
        ++i;
        --q;
        }
        for(int j=0;j<i;++j)
            {
            cout<<answer[j]<<"\n";
            }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
short q;
cin>>q;
long long l,r;
for(int i=0;i<q;++i)
    {
    cin>>l>>r;
    if(l==r){
        if(l%2==1)
            cout<<-l<<"\n";
        else cout<<l<<"\n";
        continue;
    }
    if(r-l==1)
        {
        if(r%2==1)
            cout<<-1<<"\n";
        else
            cout<<1<<"\n";
        continue;
        }
    if((r-l+1)%2==0)
        {
            if(r%2==1)
                cout<<-(r-l-1)<<"\n";
            else
                cout<<r-l-1<<"\n";
        }
    else
        {
        if(r%2==1)
            cout<<-(r-l-1)-l<<"\n";
        else
            cout<<r-l-1<<"\n";
        }
    }

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
int q;
cin>>q;
long long l,r;
long long temp_l,temp_r;
for(int i=0;i<q;++i)
    {
        cin>>l>>r;
        temp_l=((l-1)&1)?-(l)/2:(l-1)/2;
        temp_r=(r&1)?-(r+1)/2:r/2;
        cout<<temp_r-temp_l<<"\n";
    }

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
int q;
cin>>q;
long long l,r;
long long temp_l,temp_r;
for(int i=0;i<q;++i)
    {
        cin>>l>>r;
        temp_l=((l-1)&1)?-(l-2)/2:(l-1)/2;
        temp_r=(r&1)?-(r-1)/2:r/2;
        cout<<temp_r-temp_l<<"\n";
    }

}


#include <iostream>

using namespace std;

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

    short q;

    cin>>q;

    int l,r;
    long long answer[100]={};
    int l_pos_odd,l_pos_even,r_pos_odd,r_pos_even;
    short i=0;
    long long o_2,o_1,check;
    while(q)
        {
        cin>>l>>r;
/*        if(l%2==1)
            {
            l_pos_odd=l;
            l_pos_even=l+1;
            }
        else
            {
            l_pos_odd=l+1;
            l_pos_even=l;
            };
        if(r%2==1)
            {
            r_pos_odd=r;
            r_pos_even=r-1;
            }
        else
            {
            r_pos_odd=r-1;
            r_pos_even=r;
            };*/
        if(l%2==1)
            {
            if(r%2==1) answer[i]=(r-l)/-2-l;
            else answer[i]=(r-l+1)/2;
            }
        else
            {
            if(r%2==0) answer[i]=(r-l)/2+l;
            else answer[i]=-(r-l+1)/2;
            }
        /*
             o_1=r_pos_odd+l_pos_odd;
             o_2=r_pos_odd-l_pos_odd;
        if(r_pos_odd>=l_pos_odd){
                answer[i]-=o_1/2;
        answer[i]*=(o_2/2+1);
        }
        o_1=r_pos_even+l_pos_even;
        o_2=r_pos_even-l_pos_even;
        check=0;
        if(r_pos_even>=l_pos_even) {
                check+=o_1/2;
          check*=(o_2/2+1);}
          answer[i]+=check;*/
        //if(r_pos_even==l_pos_even) answer[i]+=r_pos_even;
        //if(r_pos_odd==l_pos_odd) answer[i]-=r_pos_odd;
        ++i;
        --q;
        }
        for(int j=0;j<i;++j)
            {
            cout<<answer[j]<<"\n";
            }
}


#include <iostream>

using namespace std;

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

    short q;

    cin>>q;

    int l,r;
    long long answer[100]={};
    int l_pos_odd,l_pos_even,r_pos_odd,r_pos_even;
    short i=0;
    long long o_2,o_1,check;
    while(q)
        {
        cin>>l>>r;
        if(l%2==1)
            {
            l_pos_odd=l;
            l_pos_even=l+1;
            }
        else
            {
            l_pos_odd=l+1;
            l_pos_even=l;
            };
        if(r%2==1)
            {
            r_pos_odd=r;
            r_pos_even=r-1;
            }
        else
            {
            r_pos_odd=r-1;
            r_pos_even=r;
            };
             o_1=r_pos_odd+l_pos_odd;
             o_2=r_pos_odd-l_pos_odd;
        if(r_pos_odd>=l_pos_odd){
                answer[i]-=o_1/2;
        answer[i]*=(o_2/2+1);
        }
        o_1=r_pos_even+l_pos_even;
        o_2=r_pos_even-l_pos_even;
        check=0;
        if(r_pos_even>=l_pos_even) {
                check+=o_1/2;
          check*=(o_2/2+1);}
          answer[i]+=check;
        //if(r_pos_even==l_pos_even) answer[i]+=r_pos_even;
        //if(r_pos_odd==l_pos_odd) answer[i]-=r_pos_odd;
        ++i;
        --q;
        }
        for(int j=0;j<i;++j)
            {
            cout<<answer[j]<<"\n";
            }
}