#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define lb long double
#define mp make_pair
#define pb push_back
#define loop(i,start,n) for(ll i=start;i<n;i++)
#define rloop(i,n,start)for(ll i=n;i>=start;i--)
#define mod 1000000007
#define endl "\n"
#define INF     1e15
#define NEG_INF -1e15
#define pll pair<ll,ll>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr << #x << ": " << x << "\n";
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << "\n";
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << "\n";
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << "\n";
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;
int main()
{
	IOS;
	ll n;
	cin>>n;
	ll a[n+1]={0},dp[n+1]={0};
	ll flag=0;
	loop(i,1,n+1)
	{
		cin>>a[i];
		if(a[i]<a[i-1])
			flag=1;
	}

	stack<ll> s;
	ll ans=0;
	loop(i,1,n+1)
	{
		if(s.empty()||a[i]<s.top())
		{

			dp[a[i]]=0;
			s.push(a[i]);
		}
		else
		{
			ll temp=0;
			while(!s.empty()&&s.top()<a[i])
			{

				temp=max(temp,dp[s.top()]);
				ans=max(ans,dp[s.top()]);
				s.pop();
			}
			if(!s.empty())
				dp[s.top()]=temp+1;
			s.push(a[i]);
		}
		//trace1(ans);
	}
	if(flag==0)
		ans=-1;
	cout<<ans+1;

}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define lb long double
#define mp make_pair
#define pb push_back
#define loop(i,start,n) for(ll i=start;i<n;i++)
#define rloop(i,n,start)for(ll i=n;i>=start;i--)
#define mod 1000000007
#define endl "\n"
#define INF     1e15
#define NEG_INF -1e15
#define pll pair<ll,ll>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr << #x << ": " << x << "\n";
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << "\n";
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << "\n";
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << "\n";
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;
int main()
{
	IOS;
	ll n;
	cin>>n;
	ll a[n+1]={0},dp[n+1]={0};
	ll flag=0;
	loop(i,1,n+1)
	{
		cin>>a[i];
		if(a[i]<a[i-1])
			flag=1;
	}

	stack<ll> s;
	ll ans=0;
	loop(i,1,n+1)
	{
		if(s.empty()||a[i]<s.top())
		{
			s.push(a[i]);
		}
		else
		{
			ll temp=0;
			while(!s.empty()&&s.top()<a[i])
			{

				temp=max(temp,dp[s.top()]);
				s.pop();
			}
			if(!s.empty())
			{
				//trace1(s.top());
				dp[s.top()]=temp+1;
				ans=max(ans,dp[s.top()]);
			}
			s.push(a[i]);
		}
		//trace1(ans);
	}
	//if(flag==0)
	//	ans=-1;
	cout<<ans+1;

}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define lb long double
#define mp make_pair
#define pb push_back
#define loop(i,start,n) for(ll i=start;i<n;i++)
#define rloop(i,n,start)for(ll i=n;i>=start;i--)
#define mod 1000000007
#define endl "\n"
#define INF     1e15
#define NEG_INF -1e15
#define pll pair<ll,ll>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr << #x << ": " << x << "\n";
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << "\n";
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << "\n";
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << "\n";
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;
int main()
{
	IOS;
	ll n;
	cin>>n;
	ll a[n+1]={0},dp[200000]={0};

	loop(i,1,n+1)
		cin>>a[i];

	stack<ll> s;
	ll ans=-1;
	loop(i,1,n+1)
	{
		if(s.empty()||a[i]<s.top())
		{
			s.push(a[i]);
			continue;
		}
		else
		{
			ll temp=0;
			while(!s.empty()&&s.top()<a[i])
				s.pop();

			if(!s.empty())
			{
				dp[s.top()]=dp[s.top()]+1;
				ll temp=dp[s.top()];
				ans=max(ans,temp);
				ll a1=s.top();
				s.pop();

				while(1)
				{
					//trace2(a1,temp);
					if(s.empty()||temp<=dp[s.top()])
					{
						s.push(a1);
						dp[a1]=temp;
						break;
					}
					a1=s.top();
					s.pop();

				}

			}
			//trace1(s.top());
			s.push(a[i]);
		}
		//trace1(ans);
	}
	cout<<ans+1;

}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define lb long double
#define mp make_pair
#define pb push_back
#define loop(i,start,n) for(ll i=start;i<n;i++)
#define rloop(i,n,start)for(ll i=n;i>=start;i--)
#define mod 1000000007
#define endl "\n"
#define INF     1e15
#define NEG_INF -1e15
#define pll pair<ll,ll>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr << #x << ": " << x << "\n";
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << "\n";
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << "\n";
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << "\n";
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;
int main()
{
	IOS;
	ll n;
	cin>>n;
	ll a[n+1]={0},dp[200000]={0};

	ll flag=0;
	loop(i,1,n+1)
	{
		if(a[i-1]>a[i])
			flag=1;
		cin>>a[i];
	}

	stack<ll> s;
	ll ans=0;

	loop(i,1,n+1)
	{
		if(s.empty()||a[i]<s.top())
		{
			s.push(a[i]);
			continue;
		}
		else
		{
			ll temp=0;
			while(!s.empty()&&s.top()<a[i])
				s.pop();

			if(!s.empty())
			{
				dp[s.top()]=dp[s.top()]+1;
				ll temp=dp[s.top()];
				ans=max(ans,temp);
				ll a1=s.top();
				s.pop();

				while(1)
				{
					//trace2(a1,temp);
					if(s.empty()||temp<=dp[s.top()])
					{
						s.push(a1);
						dp[a1]=temp;
						break;
					}
					a1=s.top();
					s.pop();

				}

			}
			//trace1(s.top());
			s.push(a[i]);
		}
		//trace1(ans);
	}
	if(flag==0)
		ans=-1;
	cout<<ans+1;

}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define vi vector<ll>
#define pii pair<ll, ll>
#define vii vector<pii>
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define MOD 1000000007
#define INT_MAXI 9000000000000000000
#define INT_MINI -9000000000000000000

ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}

const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main()
{

	fio;

    ll t,i,j,n,d,x,p,y,k,l,r;

    cin>>n;
    ll arr[n];
    for(i=0;i<n;i++)
    {
    	cin>>arr[i];
	}
	stack<pii>s;
	ll ans=0;
	for(i=n-1;i>=0;i--)
	{
		ll count=0,count2=0;
		while(!s.empty()&&arr[i]>s.top().fi)
		{
		//	cout<<"a";
		//	count++;
		//	cout<<s.top().fi<<" "<<s.top().se<<endl;
		    if(s.top().se==0)
		    {
		    	count++;

			}
			else
			{
				if(s.top().se-count2>0)
				count+=s.top().se-count2;
				else if(s.top()-count2==0)
				count++;
			}
			s.pop();
			count2++;
		}
	//	cout<<count<<endl;
		ans=max(ans,count);
		s.push(mp(arr[i],count));
	}
	cout<<ans;

}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define vi vector<ll>
#define pii pair<ll, ll>
#define vii vector<pii>
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define MOD 1000000007
#define INT_MAXI 9000000000000000000
#define INT_MINI -9000000000000000000

ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}

const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main()
{

	fio;

    ll t,i,j,n,d,x,p,y,k,l,r;

    cin>>n;
    ll arr[n];
    for(i=0;i<n;i++)
    {
    	cin>>arr[i];
	}
	stack<pii>s;
	ll ans=0;
	for(i=n-1;i>=0;i--)
	{
		ll count=0,count2=0;
		while(!s.empty()&&arr[i]>s.top().fi)
		{
	        count++;
	        count=max(count,s.top().se);
	        s.pop();
		}
	//	cout<<count<<endl;
		ans=max(ans,count);
		s.push(mp(arr[i],count));
	}
	cout<<ans;

}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define vi vector<ll>
#define pii pair<ll, ll>
#define vii vector<pii>
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define MOD 1000000007
#define INT_MAXI 9000000000000000000
#define INT_MINI -9000000000000000000

ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}

const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main()
{

	fio;

    ll t,i,j,n,d,x,p,y,k,l,r;

    cin>>n;
    ll arr[n];
    for(i=0;i<n;i++)
    {
    	cin>>arr[i];
	}
	stack<ll>s;
	ll ans=0;
	for(i=n-1;i>=0;i--)
	{
		ll count=0;
		while(!s.empty()&&arr[i]>s.top())
		{
			count++;
			s.pop();
		}
		ans=max(ans,count);
		s.push(arr[i]);
	}
	cout<<ans;

}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define vi vector<ll>
#define pii pair<ll, ll>
#define vii vector<pii>
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define MOD 1000000007
#define INT_MAXI 9000000000000000000
#define INT_MINI -9000000000000000000

ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}

const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main()
{

	fio;

    ll t,i,j,n,d,x,p,y,k,l,r;

    cin>>n;
    ll arr[n];
    for(i=0;i<n;i++)
    {
    	cin>>arr[i];
	}
	stack<pii>s;
	ll ans=0;
	for(i=n-1;i>=0;i--)
	{
		ll count=0,count2=0;
		while(!s.empty()&&arr[i]>s.top().fi)
		{
		//	cout<<"a";
		//	count++;
		//	cout<<s.top().fi<<" "<<s.top().se<<endl;
		    if(s.top().se==0)
		    {
		    	count++;

			}
			else
			{
				if(s.top().se-count2>0)
				count+=s.top().se-count2;
				else
				count++;
			}
			s.pop();
			count2++;
		}
	//	cout<<count<<endl;
		ans=max(ans,count);
		s.push(mp(arr[i],count));
	}
	cout<<ans;

}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define vi vector<ll>
#define pii pair<ll, ll>
#define vii vector<pii>
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define MOD 1000000007
#define INT_MAXI 9000000000000000000
#define INT_MINI -9000000000000000000

ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}

const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main()
{

	fio;

    ll t,i,j,n,d,x,p,y,k,l,r;

    cin>>n;
    ll arr[n];
    for(i=0;i<n;i++)
    {
    	cin>>arr[i];
	}
	stack<pii>s;
	ll ans=0;
	for(i=n-1;i>=0;i--)
	{
		ll count=0,count2=0;
		while(!s.empty()&&arr[i]>s.top().fi)
		{
		//	cout<<"a";
		//	count++;
		//	cout<<s.top().fi<<" "<<s.top().se<<endl;
		    if(s.top().se==0)
		    {
		    	count++;

			}
			else
			{
				if(s.top().se-count2>0)
				count+=s.top().se-count2;
				else if(s.top().se-count2==0)
				count++;
			}
			s.pop();
			count2++;
		}
	//	cout<<count<<endl;
		ans=max(ans,count);
		s.push(mp(arr[i],count));
	}
	cout<<ans;

}


#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef long double     ld;
typedef string          str;
#define all(x)			(x).begin(),(x).end()
#define Sort(x)			sort(all(x))
#define A               first
#define B               second
#define sep             ' '
#define endl            '\n'
#define fast_io         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int MAX1 = 5e5 + 7;

ll n, ans, mod = 1e9+7, num[MAX1], tim[MAX1];
string s;
vector <ll> vec;

int main(){
    cin >> n;
    for (int i = 1; i <= n; ++i){
    	cin >> num[i];
    	tim[i] = 1;
    	while (!vec.empty() && num[vec.back()] < num[i]){
    		// cout << i << endl;
    		tim[i] = max(tim[vec.back()]+1, tim[i]);
    		// cout << i << sep << tim[vec.back()] << endl;
    		vec.pop_back();
		}
		if (vec.empty())	tim[i] = 0;
		// cout << i << sep << sep << tim[i] << endl;
		ans = max(ans, tim[i]);
		vec.push_back(i);
	}
	cout << ans;
    return 0;
}
/*                now or never                         */


#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef long double     ld;
typedef string          str;
#define all(x)			(x).begin(),(x).end()
#define Sort(x)			sort(all(x))
#define A               first
#define B               second
#define sep             ' '
#define endl            '\n'
#define fast_io         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int MAX1 = 5e4 + 7;

ll n, ans, mod = 1e9+7, num[MAX1], tim[MAX1];
string s;
vector <ll> vec;

int main(){
    cin >> n;
    for (int i = 1; i <= n; ++i){
    	cin >> num[i];
    	tim[i] = 1;
    	while (!vec.empty() && num[vec.back()] < num[i]){
    		// cout << i << endl;
    		tim[i] = max(tim[vec.back()]+1, tim[i]);
    		// cout << i << sep << tim[vec.back()] << endl;
    		vec.pop_back();
		}
		if (vec.empty())	tim[i] = 0;
		// cout << i << sep << sep << tim[i] << endl;
		ans = max(ans, tim[i]);
		vec.push_back(i);
	}
	cout << ans;
    return 0;
}
/*                now or never                         */


#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef long double     ld;
typedef string          str;
#define all(x)			(x).begin(),(x).end()
#define Sort(x)			sort(all(x))
#define A               first
#define B               second
#define sep             ' '
#define endl            '\n'
#define fast_io         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int MAX1 = 5e4 + 7;

ll n, ans, mod = 1e9+7, num[MAX1], tim[MAX1];
string s;
vector <ll> vec;

int main(){
    cin >> n;
    for (int i = 1; i <= n; ++i){
    	cin >> num[i];
    	tim[i] = 1;
    	while (!vec.empty() && num[vec.back()] <= num[i]){
    		// cout << i << endl;
    		tim[i] = tim[vec.back()]+1;
    		vec.pop_back();
		}
		if (vec.empty())	tim[i] = 0;
		// cout << i << sep << tim[i] << endl;
		ans = max(ans, tim[i]);
		vec.push_back(i);
	}
	cout << ans;
    return 0;
}
/*                now or never                         */


#include <bits/stdc++.h>

using namespace std;

typedef long long       ll;
typedef long double     ld;
typedef string          str;

#define all(x)			(x).begin(),(x).end()
#define Sort(x)			sort(all(x))
#define A               first
#define B               second
#define sep             ' '
#define endl            '\n'
#define fast_io         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const ll MAX1 = 3e5+10;

ll a, b, n, k, c, d, e, f, x, y, l, r, z, mid,  num[MAX1], cnt, flag, p[MAX1], ans[MAX1];
string s;

int main(){
	cin >> a;
	for (int i = 0; i < a; ++i) cin >> num[i];
	flag = -1;
	for (int i = 0; i < a; ++i){
        if (flag < num[i])  flag = -1, x = max(cnt, x);
        else if (num[i] > num[i-1]) ++cnt;
        if (flag == -1) flag = num[i];
	}
	x = max(cnt, x);
	cout << x;
	return 0;
}
/*                          now or never                         */


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int32_t main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i<n; i++){
        cin >> a[i];
    }

    stack<pair<int, int>> s;
    s.push({a[0], 0});
    int ans = 0;
    for(int i = 1; i<n; i++){
        int temp = 0;
        while(!s.empty()){
            if(s.top().first < a[i]){
                temp = max(temp, s.top().second);
                s.pop();
            }
            else{
                break;
            }
        }
        if(s.empty()){
            temp = 0;
        }
        else{
            temp++;
        }
        s.push({a[i], temp});
        ans = max(ans, temp);
    }
    cout << ans << "\n";
    return 0;
}


#include<iostream>
using namespace std;
int main()
{int t;
cin>>t;
while(t--)
{
    int a,b,flag=0;
    cin>>a>>b;
    if(a==b)
        flag=0;
    else if(a>b)
    {
        if((a-b)%2==0)
            flag=1;
        else
            flag=2;
    }
    else if(a<b)
    {
        if((a%2==0&b%2==0)||(a%2!=0&b%2!=0))
            flag=2;
        else
            flag=1;
    }
    cout<<flag<<'\n';
}

return 0;}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define mm(a) memset(a,0,sizeof(a))
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0)
#define ll long long
using namespace std;
int main(void)
{
    sync;
    int t;
    cin>>t;
    while(t--)
    {
        int a,b;
        cin>>a>>b;
        if(a==b)
            cout<<0<<endl;
        else if(a>b)
        {
            if(!((a-b)&1))
                cout<<1<<endl;
            else
                cout<<2<<endl;
        }
        else
        {
            if((b-a)&1)
                cout<<1<<endl;
            else
                cout<<2<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define mm(a) memset(a,0,sizeof(a))
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0)
#define ll long long
using namespace std;
int main(void)
{
    sync;
    int t;
    cin>>t;
    while(t--)
    {
        int a,b;
        cin>>a>>b;
        if(a==b)
            cout<<0<<endl;
        else if(a>b)
        {
            if(!(a-b)&1)
                cout<<1<<endl;
            else
                cout<<2<<endl;
        }
        else
        {
            if((b-a)&1)
                cout<<1<<endl;
            else
                cout<<2<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define mm(a) memset(a,0,sizeof(a))
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0)
#define ll long long
using namespace std;
int main(void)
{
    sync;
    int t;
    cin>>t;
    while(t--)
    {
        int a,b;
        cin>>a>>b;
        if(a==b)
            cout<<0<<endl;
        else if(a>b)
        {
            if(!(a-b)&1)
                cout<<2<<endl;
            else
                cout<<1<<endl;
        }
        else
        {
            if((b-a)&1)
                cout<<1<<endl;
            else
                cout<<2<<endl;
        }
    }
    return 0;
}


//#include<bits/stdc++.h>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int t;
int main()
{
	int a, b;bool sign1, sign2;
	cin >> t;
	while (t--)
	{
		cin >> a >> b;
		if (a == b)cout << "0" << endl;
		else {

			if (a % 2 == 1)sign1 = true;
			else sign1 = false;
			if (b % 2 == 1)sign2 = true;
			else sign2 = false;
			//判断jiou；
			if (a > b) { if (sign1 == true && sign2 == false)cout << "2" << endl;
			else if(sign1 == true && sign2 == true)cout << "1" << endl;
			else if(sign1 == false && sign2 == false)cout << "1" << endl;
			else if (sign1 == false && sign2 == true)cout << "2" << endl;
			}
			else if (a< b) {
				if (sign1 == true && sign2 == false)cout << "1" << endl;
				else if (sign1 == true && sign2 == true)cout << "1" << endl;
				else if (sign1 == false && sign2 == false)cout << "2" << endl;
				else if (sign1 == false && sign2 == true)cout << "1" << endl;

			}

		}

	}
	return 0;

}


//#include<bits/stdc++.h>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int t;
int main()
{
	long int a, b;bool sign1, sign2;
	cin >> t;
	while (t--)
	{
		cin >> a >> b;
		if (a == b)cout << "0" << endl;
		else {

			if (a % 2 == 1)sign1 = true;
			else sign1 = false;
			if (b % 2 == 1)sign2 = true;
			else sign2 = false;
			//判断jiou；
			if (a > b) { if (sign1 == true && sign2 == false)cout << "2" << endl;
			else if(sign1 == true && sign2 == true)cout << "1" << endl;
			else if(sign1 == false && sign2 == false)cout << "1" << endl;
			else if (sign1 == false && sign2 == true)cout << "2" << endl;
			}
			else if (a< b) {
				if (sign1 == true && sign2 == false)cout << "1" << endl;
				else if (sign1 == true && sign2 == true)cout << "2" << endl;
				else if (sign1 == false && sign2 == false)cout << "2" << endl;
				else if (sign1 == false && sign2 == true)cout << "1" << endl;

			}

		}

	}
	return 0;

}


//#include<bits/stdc++.h>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int t;
int main()
{
	long int a, b;bool sign1, sign2;
	cin >> t;
	while (t--)
	{
		cin >> a >> b;
		if (a == b)cout << "0" << endl;
		else {

			if (a % 2 == 1)sign1 = true;
			else sign1 = false;
			if (b % 2 == 1)sign2 = true;
			else sign2 = false;
			//判断jiou；
			if (a > b) { if (sign1 == true && sign2 == false)cout << "2" << endl;
			else if(sign1 == true && sign2 == true)cout << "1" << endl;
			else if(sign1 == false && sign2 == false)cout << "1" << endl;
			else if (sign1 == false && sign2 == true)cout << "2" << endl;
			}
			else if (a< b) {
				if (sign1 == true && sign2 == false)cout << "1" << endl;
				else if (sign1 == true && sign2 == true)cout << "1" << endl;
				else if (sign1 == false && sign2 == false)cout << "2" << endl;
				else if (sign1 == false && sign2 == true)cout << "1" << endl;

			}

		}

	}
	return 0;

}


#include <iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
#define f(n) for(int i=0;i<n;i++)
 string s;
 int t, a, b;;
int main() {
    cin >> t;
    while (t--) {
        cin >> a >> b;
        if (a == b)
            cout << 0<<endl;
        else if (a < b)
        {
            if ((b - a) % 2 == 0)
                cout << 2<<endl;
            else cout << 1<<endl;
        }
        else {
            if ((a - b) % 2 == 0)
                cout << 1<<endl;
            else cout << 2<<endl;
        }
    }

    return 0;
}


#include <iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
#define f(n) for(int i=0;i<n;i++)
 string s;
 int t, a, b;;
int main() {
    cin >> t;
    while (t--) {
        cin >> a >> b;
        if (a == b)
            cout << 0;
        else if (a < b)
        {
            if ((b - a) % 2 == 0)
                cout << 2;
            else cout << 1;
        }
        else {
            if ((a - b) % 2 == 0)
                cout << 1;
            else cout << 2;
        }
    }

    return 0;
}


#include <fstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

int n;

int main(){
  freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w+", stdout);
  cin >> n;

  for(int i; i < n; i++){
    int a,b;
    cin >> a >> b;
    if(a==b){
      cout << 0 << endl;

    }
    else if(a<b){
      if (a%2 == b%2){
        cout << 2 << endl;
      }
      else{
        cout << 1 << endl;
      }
    }
    else{
      if(a%2 == b%2){
        cout << 1 << endl;
      }
      else{
        cout << 2 << endl;
      }
    }
  }
  return 0;
}


//#include <fstream>
#include <iostream>
//#include <string>
//#include <algorithm>
//#include <vector>
#include <stdio.h>

using namespace std;

int main(){
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w+", stdout);

  int n;
  cin >> n;

  for(int i; i < n; i++){
    int a,b;
    cin >> a >> b;
    if(a==b){
      cout << 0 << endl;

    }
    else if(a<b){
      if (a%2 == b%2){
        cout << 2 << endl;
      }
      else{
        cout << 1 << endl;
      }
    }
    else{
      if(a%2 == b%2){
        cout << 1 << endl;
      }
      else{
        cout << 2 << endl;
      }
    }
  }
  return 0;
}


#include <fstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int n;

int main(){
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w+", stdout);
  cin >> n;

  for(int i; i < n; i++){
    int a,b;
    cin >> a >> b;
    if(a==b){
      cout << 0 << endl;

    }
    else if(a<b){
      if (a%2 == b%2){
        cout << 2 << endl;
      }
      else{
        cout << 1 << endl;
      }
    }
    else{
      if(a%2 == b%2){
        cout << 1 << endl;
      }
      else{
        cout << 2 << endl;
      }
    }
  }
  //return 0;
}


//#include <fstream>
#include <iostream>
//#include <string>
//#include <algorithm>
//#include <vector>
#include <stdio.h>

using namespace std;

int main(){
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w+", stdout);

  int n;
  cin >> n;

  for(int i = 0; i < n; i++){
    int a,b;
    cin >> a >> b;
    if(a==b){
      cout << 0 << endl;

    }
    else if(a<b){
      if (a%2 == b%2){
        cout << 2 << endl;
      }
      else{
        cout << 1 << endl;
      }
    }
    else{
      if(a%2 == b%2){
        cout << 1 << endl;
      }
      else{
        cout << 2 << endl;
      }
    }
  }
  return 0;
}


#include <fstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stdio.h>

using namespace std;

int n;

int main(){
  freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w+", stdout);
  cin >> n;

  for(int i; i < n; i++){
    int a,b;
    cin >> a >> b;
    if(a==b){
      cout << 0 << endl;

    }
    else if(a<b){
      if (a%2 == b%2){
        cout << 2 << endl;
      }
      else{
        cout << 1 << endl;
      }
    }
    else{
      if(a%2 == b%2){
        cout << 1 << endl;
      }
      else{
        cout << 2 << endl;
      }
    }
  }
  return 0;
}


#include <fstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int n;

int main(){
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w+", stdout);
  cin >> n;

  for(int i; i < n; i++){
    int a,b;
    cin >> a >> b;
    if(a==b){
      cout << "0" << endl;

    }
    else if(a<b){
      if (a%2 == b%2){
        cout << "2" << endl;
      }
      else{
        cout << "1" << endl;
      }
    }
    else{
      if(a%2 == b%2){
        cout << "1" << endl;
      }
      else{
        cout << "2" << endl;
      }
    }
  }
  return 0;
}


#include <fstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int n;

int main(){
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w+", stdout);
  cin >> n;

  for(int i; i < n; i++){
    int a,b;
    cin >> a >> b;
    if(a==b){
      cout << 0 << endl;

    }
    else if(a<b){
      if (a%2 == b%2){
        cout << 2 << endl;
      }
      else{
        cout << 1 << endl;
      }
    }
    else{
      if(a%2 == b%2){
        cout << 1 << endl;
      }
      else{
        cout << 2 << endl;
      }
    }
  }
  return 0;
}


#include <iostream>

using namespace std;

int main() {
#ifdef _DEBUG
	//freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

	int t;
	cin >> t;
	while (t--) {
		int a, b;
		cin >> a >> b;
		if (a == b) cout << 0 << endl;
		else cout << 1 + int((a < b) ^ ((b - a) & 1)) << endl;
	}

	return 0;
}


#include <fstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int n;

int main(){
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w+", stdout);
  cin >> n;

  for(int i; i < n; i++){
    int a,b;
    cin >> a >> b;
    if(a==b){
      cout << "0" << endl;

    }
    else if(a<b){
      if (a%2 == b%2){
        cout << "2" << endl;
      }
      else{
        cout << "1" << endl;
      }
    }
    else{
      if(a%2 == b%2){
        cout << "1" << endl;
      }
      else{
        cout << "2" << endl;
      }
    }
  }
  return 0;
}


#include <fstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stdio.h>

using namespace std;

int n;

int main(){
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w+", stdout);
  cin >> n;

  for(int i; i < n; i++){
    int a,b;
    cin >> a >> b;
    if(a==b){
      cout << "0" << endl;

    }
    else if(a<b){
      if (a%2 == b%2){
        cout << "2" << endl;
      }
      else{
        cout << "1" << endl;
      }
    }
    else{
      if(a%2 == b%2){
        cout << "1" << endl;
      }
      else{
        cout << "2" << endl;
      }
    }
  }
  return 0;
}


#include <fstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int n;

int main(){
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w+", stdout);
  cin >> n;

  for(int i; i < n; i++){
    int a,b;
    cin >> a >> b;
    if(a==b){
      cout << "0" << endl;

    }
    else if(a<b){
      if (a%2 == b%2){
        cout << "2" << endl;
      }
      else{
        cout << "1" << endl;
      }
    }
    else{
      if(a%2 == b%2){
        cout << "1" << endl;
      }
      else{
        cout << "2" << endl;
      }
    }
  }
  //return 0;
}


#include <fstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int n;

int main(){
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w+", stdout);
  cin >> n;

  for(int i; i < n; i++){
    int a,b;
    cin >> a >> b;
    if(a==b){
      cout << 0 << endl;

    }
    else if(a<b){
      if (a%2 == b%2){
        cout << 2 << endl;
      }
      else{
        cout << 1 << endl;
      }
    }
    else{
      if(a%2 == b%2){
        cout << 1 << endl;
      }
      else{
        cout << 2 << endl;
      }
    }
  }
  return 0;
}


#include <fstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int n;

int main(){
  freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w+", stdout);
  cin >> n;

  for(int i; i < n; i++){
    int a,b;
    cin >> a >> b;
    if(a==b){
      cout << 0 << endl;

    }
    else if(a<b){
      if (a%2 == b%2){
        cout << 2 << endl;
      }
      else{
        cout << 1 << endl;
      }
    }
    else{
      if(a%2 == b%2){
        cout << 1 << endl;
      }
      else{
        cout << 2 << endl;
      }
    }
  }
  return 0;
}


#define _DEBUG

#include <iostream>

using namespace std;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

	int t;
	cin >> t;
	while (t--) {
		int a, b;
		cin >> a >> b;
		if (a == b) cout << 0 << endl;
		else cout << 1 + int((a < b) ^ ((b - a) & 1)) << endl;
	}

	return 0;
}


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

int main() {
	int a, b, t;
	cin >> t;
	for (int i = 0; i < t; ++i) {
		cin >> a >> b;
		if (a == b) cout << 0 << endl;
		else if (a > b && (a - b) % 2 == 0)
			cout << 1 << endl;
		else
			cout << 2 << endl;
	}
	return 0;
}


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

int main() {
	int a, b, t;
	cin >> t;
	for (int i = 0; i < t; ++i) {
		cin >> a >> b;
		if (a == b) cout << 0 << endl;
		else if ((a > b && (a - b) % 2 == 0) || (a < b && (b - a) % 2 != 0))
			cout << 1 << endl;
		else
			cout << 2 << endl;
	}
	return 0;
}


#include <iostream>
using namespace std;
int main() {
    int t;
    cin>>t;
    while(t--){
        long long int a, b;
        cin>>a>>b;
        long long int diff = a-b;
        if(diff>0){
            if(diff%2==0){
                cout<<1<<endl;
            }
            else{
                cout<<2<<endl;
            }
        }
        else if(diff==0){
            cout<<0<<endl;
        }
        else{
            if(diff%2==0){
                cout<<2<<endl;
            }
            else{
                cout<<1<<endl;
            }
        }
    }
    return 0;
}


#include <iostream>
using namespace std;
int main() {
    int t;
    cin>>t;
    long long int a, b;
    while(t--){
        cin>>a>>b;
        long long int diff = a-b;
        if(diff>0){
            //a>b -> subtract something from a
            if(diff%2==0){
                cout<<1<<endl;
            }
            else{
                cout<<2<<endl;
            }
        }
        else if(diff==0){
            cout<<0<<endl;
        }
        else{
            if(diff%2==0){
                cout<<2<<endl;
            }
            else{
                cout<<1<<endl;
            }
        }
    }
    return 0;
}


#include <cstdio>
int main(void) {
	int test_case;
	scanf("%d", &test_case);

	for (int i = 0; i < test_case; i++) {
		int a, b;
		int answer = 2;
		scanf("%d %d", &a, &b);

		if (a == b)
			answer = 0;
		else if (((a > b) && ((a - b) % 2 == 0)) || ((a < b) && ((b - a) % 2 == 1)))
			answer = 1;

		printf("%d\n", answer);
	}

	return 0;
}


#include <cstdio>
int main(void) {
	int test_case;
	scanf("%d", &test_case);

	for (int i = 0; i < test_case; i++) {
		int a, b;
		int answer = 2;
		scanf("%d %d", &a, &b);

		if (a == b)
			answer = 0;
		if (((a > b) && ((a - b) % 2 == 0)) || ((a < b) && ((b - a) % 2 == 1)))
			answer = 1;

		printf("%d\n", answer);
	}

	return 0;
}


#include <cstdio>
int main(void) {
	int test_case;
	scanf("%d", &test_case);

	for (int i = 0; i < test_case; i++) {
		int a, b;
		scanf("%d %d", &a, &b);

		if (a == b)
			printf("0\n");
		else if (a > b) {
			if ((a - b) % 2 == 0)
				printf("1\n");
			else
				printf("2\n");
		}
		else {
			if ((b - a) % 2 == 0)
				printf("2\n");
			else
				printf("1\n");
		}
	}

	return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int t, a, b;
    cin >> t;
    for (int i = 0; i < t; i++)
    {
        cin >> a >> b;
        int z1 = a - b;
        if (z1 < 0)
            z1 = z1 * -1;

        if (a > b)
        {
            if (z1==1)
                cout << 2<<endl;
            if (z1==2)
                cout << 1;
            if (z1 >= 3)
            {
                if (z1 % 2 == 0)
                    cout << 1 << endl;
                else
                    cout << 2<< endl;
            }
        }
        if (b > a)
        {
            if (z1 == 1)
                cout << 1<< endl;
            if (z1 == 2)
                cout << 2<< endl;
            if (z1 >= 3)
            {
                if (z1 % 2 == 0)
                    cout << 2<< endl;
                else
                    cout << 1<< endl;

            }

        }
        if (z1 == 0)
            cout << 0<< endl;

    }

    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int t, a, b;
    cin >> t;
    for (int i = 0; i < t; i++)
    {
        cin >> a >> b;
        int z1 = a - b;
        if (z1 < 0)
            z1 = z1 * -1;

        if (a > b)
        {
            if (z1==1)
                cout << 2;
            if (z1==2)
                cout << 1;
            if (z1 >= 3)
            {
                if (z1 % 2 == 0)
                    cout << 1;
                else
                    cout << 2;
            }
        }
        if (b > a)
        {
            if (z1 == 1)
                cout << 1;
            if (z1 == 2)
                cout << 2;
            if (z1 >= 3)
            {
                if (z1 % 2 == 0)
                    cout << 2;
                else
                    cout << 1;

            }

        }
        if (z1 == 0)
            cout << 0;

    }

    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int t, a, b;
    cin >> t;
    for (int i = 0; i < t; i++)
    {
        cin >> a >> b;
        int z1 = a - b;
        if (z1 < 0)
            z1 = z1 * -1;

        if (a > b)
        {
            if (z1==1)
                cout << 2<<endl;
            if (z1==2)
                cout << 1;
            if (z1 >= 3)
            {
                if (z1 % 2 == 0)
                    cout << 1 << endl;
                else
                    cout << 2<< endl;
            }
        }
        if (b > a)
        {
            if (z1 == 1)
                cout << 1<< endl;
            if (z1 == 2)
                cout << 2;
            if (z1 >= 3)
            {
                if (z1 % 2 == 0)
                    cout << 2<< endl;
                else
                    cout << 1<< endl;

            }

        }
        if (z1 == 0)
            cout << 0<< endl;

    }

    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int t, a, b;
    cin >> t;
    for (int i = 0; i < t; i++)
    {
        cin >> a >> b;
        int z1 = a - b;
        if (z1 < 0)
            z1 = z1 * -1;

        if (a > b)
        {
            if (z1==1)
                cout << 2<<endl;
            if (z1==2)
                cout << 1<< endl;
            if (z1 >= 3)
            {
                if (z1 % 2 == 0)
                    cout << 1 << endl;
                else
                    cout << 2<< endl;
            }
        }
        if (b > a)
        {
            if (z1 == 1)
                cout << 1<< endl;
            if (z1 == 2)
                cout << 2<< endl;
            if (z1 >= 3)
            {
                if (z1 % 2 == 0)
                    cout << 2<< endl;
                else
                    cout << 1<< endl;

            }

        }
        if (z1 == 0)
            cout << 0<< endl;

    }

    return 0;
}


#include <iostream>
using namespace std;
int main() {
  int nbNombres;
  cin >> nbNombres;
  int a, b;
  for (int iNombre = 0; iNombre < nbNombres; iNombre ++) {
    cin >> a >> b;
    if (a<b) {
      a = (a%2);
      b = (b%2);
      if (a==b) {
        cout << 2;
      }
      else {
        cout << 1;
      }
    }
    else if (a>b) {
      a = (a%2);
      b = (b%2);
      if (a==b) {
        cout << 1;
      }
      else {
        cout << 2;
      }
    }
    else {
      cout << 0;
    }
  }
}


#include <iostream>
using namespace std;
int main() {
  int nbNombres;
  cin >> nbNombres;
  int a, b;
  for (int iNombre = 0; iNombre < nbNombres; iNombre ++) {
    cin >> a >> b;
    if (a<b) {
      a = (a%2);
      b = (b%2);
      if (a==b) {
        cout << 2<< endl;
      }
      else {
        cout << 1<< endl;
      }
    }
    else if (a>b) {
      a = (a%2);
      b = (b%2);
      if (a==b) {
        cout << 1<<endl;
      }
      else {
        cout << 2<<endl;
      }
    }
    else {
      cout << 0<<endl;
    }
  }
}


#include <iostream>
#include <cmath>
int main() {
  int nbNombres;
  cin >> nbNombres;
  int a, b;
  for (int iNombre = 0; iNombre < nbNombre; iNombre ++) {
    cin >> a >> b;
    if (a<b)
      a = (a%2);
      b = (b%2);
      if (a==b) {
        cout << 2;
      }
      else {
        cout << 1;
      }
    else if (a>b) {
      a = (a%2);
      b = (b%2);
      if (a==b) {
        cout << 1;
      }
      else {
        cout << 2;
      }
    }
    else {
      cout << 0;
    }
  }
}


g++ oddeven1.cpp -o oddeven1
#include <iostream>
int main() {
  int nbNombres;
  cin >> nbNombres;
  int a, b;
  for (int iNombre = 0; iNombre < nbNombre; iNombre ++) {
    cin >> a >> b;
    if (a<b) {
      a = (a%2);
      b = (b%2);
      if (a==b) {
        cout << 2;
      }
      else {
        cout << 1;
      }
    }
    else if (a>b) {
      a = (a%2);
      b = (b%2);
      if (a==b) {
        cout << 1;
      }
      else {
        cout << 2;
      }
    }
    else {
      cout << 0;
    }
  }
}


-o g++ oddeven1.cpp oddeven1
#include <iostream>
int main() {
  int nbNombres;
  cin >> nbNombres;
  int a, b;
  for (int iNombre = 0; iNombre < nbNombre; iNombre ++) {
    cin >> a >> b;
    if (a<b) {
      a = (a%2);
      b = (b%2);
      if (a==b) {
        cout << 2;
      }
      else {
        cout << 1;
      }
    }
    else if (a>b) {
      a = (a%2);
      b = (b%2);
      if (a==b) {
        cout << 1;
      }
      else {
        cout << 2;
      }
    }
    else {
      cout << 0;
    }
  }
}


#include <iostream>
#include <cmath>
int main() {
  int nbNombres;
  cin >> nbNombres;
  int a, b;
  for (int iNombre = 0; iNombre < nbNombre; iNombre ++) {
    cin >> a >> b;
    if (a<b) {
      a = (a%2);
      b = (b%2);
      if (a==b) {
        cout << 2;
      }
      else {
        cout << 1;
      }
    }
    else if (a>b) {
      a = (a%2);
      b = (b%2);
      if (a==b) {
        cout << 1;
      }
      else {
        cout << 2;
      }
    }
    else {
      cout << 0;
    }
  }
}


#include <iostream>
using namespace std;
int main() {
  int nbNombres;
  cin >> nbNombres;
  int a, b;
  for (int iNombre = 0; iNombre < nbNombre; iNombre ++) {
    cin >> a >> b;
    if (a<b) {
      a = (a%2);
      b = (b%2);
      if (a==b) {
        cout << 2;
      }
      else {
        cout << 1;
      }
    }
    else if (a>b) {
      a = (a%2);
      b = (b%2);
      if (a==b) {
        cout << 1;
      }
      else {
        cout << 2;
      }
    }
    else {
      cout << 0;
    }
  }
}


#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int t;
	long long a, b;
	cin >> t;
	for (int i = 0; i < t; i++) {
		cin >> a >> b;
		if (a == b) {
			cout << 0 <<endl;
		}
		else if (a > b) {
			if (a % 2 == 0 && b % 2 == 0) {
				cout << 1 << endl;
			}
			else if (a % 2 == 1 && b % 2 == 1) {
				cout << 1 << endl;
			}
			else if (a % 2 == 0 && b % 2 == 1) {
				cout << 2 << endl;
			}
			else if (a % 2 == 1 && b % 2 == 0) {
				cout << 2 << endl;
			}
		}
		else {
			if (a % 2 == 0 && b % 2 == 0) {
				cout << 2 << endl;
			}
			else if (a % 2 == 1 && b % 2 == 1) {
				cout << 2 << endl;
			}
			else if (a % 2 == 0 && b % 2 == 1) {
				cout << 1 << endl;
			}
			else if (a % 2 == 1 && b % 2 == 0) {
				cout << 1<<endl;
			}
		}
	}
	//system("pause");
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int t;
	long long a, b;
	cin >> t;
	for (int i = 0; i < t; i++) {
		cin >> a >> b;
		if (a == b) {
			cout << 0<<endl;
		}
		else {
			if ((a > b && ((a % 2 == 0 && b % 2 == 0) || (a % 2 == 1 && b % 2 == 1))) || (a < b && (a % 2 == 0 && b%2==1))) {
				cout << 1 <<endl;
			}
			else cout << 2 <<endl;
		}
	}
//	system("pause");
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
long a,b;
int n;
int main(){
    cin >> n;
    for(int i =1;i<=n;i++){
        cin >> a >> b;
        if(a==b)
            cout << 0 << endl;
        if(b > a)
            cout << b-a << endl;
        if(a > b){
            if((a-b)%2==0)
                cout<< 1 << endl;
            else
            {
                cout << 2 << endl;
            }

        }
    }

    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
long a,b;
int n;
int main(){
    cin >> n;
    while(n--){
        cin >> a >> b;
        if(a==b)
            cout << 0 << endl;
        if(b > a)
            cout << b-a << endl;
        if(a > b){
            if((a-b)%2)
                cout<< 2<< endl;
            else
            {
                cout << 1 << endl;
            }

        }
    }

    return 0;
}


#include<iostream>
#include<cstdio>
using namespace;
long a,b;
int n;
int main(){
    cin >> n;
    while(n--){
        cin >> a >> b;
        if(a==b)
            cout << 0 << endl;
        if(b > a)
            cout << b-a << endl;
        if(a > b){
            if((a-b)%2)
                cout<< 2<< endl;
            else
            {
                cout << 1 << endl;
            }

        }
    }

    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
long a,b;
int n;
int main(){
    cin >> n;
    for(int i =1;i<=n;i++){
        cin >> a >> b;
        if(a==b)
            cout << 0 << endl;
        if(b > a)
            if((b-a)%2==0)
                cout<< 2 << endl;
            else
            {
                cout << 1 << endl;
            }
        if(a > b){
            if((a-b)%2==0)
                cout<< 1 << endl;
            else
            {
                cout << 2 << endl;
            }

        }
    }

    return 0;
}


#include <iostream>
using namespace std;
int main()
{
int a, b,c,d,kolvo;
cin >> a;
cin >> b;
kolvo = 0;
while (a != b)
{
if (a > b)
{
d = a - b;
c = d%2;
if (c != 0)d=d + 1;
a = a - d;
kolvo = kolvo + 1;
}
if (a < b)
{
d = b - a;
c = d % 2;
if (c == 0) { d = d - 1; }
a = a + d;
kolvo = kolvo + 1;
}
}
cout << kolvo;
}


#include <iostream>
#include<conio.h>
using namespace std;
int main()
{
	int t;
	int a, b;
	int answer[10000];
	cin >> t;
	for (int i = 0; i < t; i++)
	{
		cin >> a; cin >> b;
		if (a == b)
			answer[i] = 0;
		else if (a > b)
		{
			if ((a % 2) == 0)
			{
				if ((b % 2) == 0) answer[i] = 1;
				else answer[i] = 2;
			}
			else {
				if ((b % 2) == 0) answer[i] = 2;
				else answer[i] = 1;
			}
		}
		else {
			if ((a % 2) == 0)
			{
				if ((b % 2) == 0) answer[i] = 2;
				else answer[i] = 1;
			}
			else {
				if ((b % 2) == 0) answer[i] = 1;
				else answer[i] = 2;
			}
		}
	}
	for (int i = 0; i < t; i++)
	{
		cout << answer[i] << endl;
	}
}


#include <iostream>
#include<conio.h>
using namespace std;
int main()
{
	int t;
	long unsigned int a, b;
	int answer[1000];
	cin >> t;
	for (int  i = 0; i < t; i++)
	{
		cin >> a; cin >> b;
		if (a==b)
			answer[i]= 0;
		else if (a>b)
		{
			if ((a&1)==0)
			{
				if ((b & 1) == 0) answer[i] = 1;
				else answer[i] = 2;
			}
			else {
				if ((b & 1) == 0) answer[i] = 2;
				else answer[i] = 1;
			}
		}
		else {
			if ((a & 1) == 0)
			{
				if ((b & 1) == 0) answer[i] = 2;
				else answer[i] = 1;
			}
			else {
				if ((b & 1) == 0) answer[i] = 1;
				else answer[i] = 2;
			}
		}
	}
	for (int i = 0; i < t; i++)
	{
		cout << answer[i] << endl;
	}
}


#include <iostream>
#include<conio.h>
#include<cmath>
using namespace std;
int main()
{
	int t;
	long unsigned int a, b;
	cin >> t;
	for (int  i = 0; i < t; i++)
	{
		cin >> a; cin >> b;
		if (a==b)
			cout << "0";
		else if (a>b)
		{
			if ((a&1)==0)
			{
				if ((b & 1) == 0) cout << "1";
				else cout << "2";
			}
			else {
				if ((b & 1) == 0) cout << "2";
				else cout << "1";
			}
		}
		else {
			if ((a & 1) == 0)
			{
				if ((b & 1) == 0) cout << "2";
				else cout << "1";
			}
			else {
				if ((b & 1) == 0) cout << "1";
				else cout << "2";
			}
		}
	}
}


#include <iostream>
#include<conio.h>
#include<cmath>
using namespace std;
int main()
{
	int t;
	long unsigned int a, b;
	int answer[1000];
	cin >> t;
	for (int  i = 0; i < t; i++)
	{
		cin >> a; cin >> b;
		if (a==b)
			answer[i]= 0;
		else if (a>b)
		{
			if ((a&1)==0)
			{
				if ((b & 1) == 0) answer[i] = 1;
				else answer[i] = 2;
			}
			else {
				if ((b & 1) == 0) answer[i] = 2;
				else answer[i] = 1;
			}
		}
		else {
			if ((a & 1) == 0)
			{
				if ((b & 1) == 0) answer[i] = 2;
				else answer[i] = 1;
			}
			else {
				if ((b & 1) == 0) answer[i] = 1;
				else answer[i] = 2;
			}
		}
	}
	for (int i = 0; i < t; i++)
	{
		cout << answer[i] << endl;
	}
}


#include <iostream>
using namespace std;
int main()
{
	int a, b, c, d, kolvo, t, i;
	int massiv[10000];
	cin >> t;
	kolvo = 0;
	i = 0;
	for (int y = 0; y < t; y++)
	{
		cin >> a;
		cin >> b;
		while (a != b)
		{
			if (a > b)
			{
				d = a - b;
				c = d % 2;
				if (c != 0)d = d + 1;
				a = a - d;
				kolvo = kolvo + 1;
			}
			if (a < b)
			{
				d = b - a;
				c = d % 2;
				if (c == 0) { d = d - 1; }
				a = a + d;
				kolvo = kolvo + 1;
			}
		}
		massiv[i] = kolvo;
		i++;
		kolvo = 0;
	}
	cout << endl;
	for (int y = 0; y < t; y++)
	{
		cout << massiv[y];
		cout << endl;
	}
}


#include <iostream>
using namespace std;
int main()
{
int a, b, c, d, kolvo, t,i;
int massiv[10000];
cin >> t;
kolvo = 0;
i = 0;
for (int y = 0; y < t; y++)
{
cin >> a;
cin >> b;
while (a != b)
{
if (a > b)
{
d = a - b;
c = d % 2;
if (c != 0)d = d + 1;
a = a - d;
kolvo = kolvo + 1;
}
if (a < b)
{
d = b - a;
c = d % 2;
if (c == 0) { d = d - 1; }
a = a + d;
kolvo = kolvo + 1;
}
}
massiv[i] = kolvo;
i++;
kolvo = 0;
}
cout « endl;
for (int y = 0; y < t; y++)
{
cout << massiv[y];
cout << endl;
}
}


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

            }
            else
            cout<<0<<endl;
      }
      return 0;
}


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

            }
            else
            cout<<0<<endl;
      }
      return 0;
}


#include<iostream>
using namespace std;
int main(){
      int t;
      cin>>t;
      while(t--){
            long long int a,b;
            cin>>a>>b;
            if(a>b){
                  if((a-b)%2==0)
                  cout<<1<<endl;
                  else
                  cout<<2<<endl;
            }
            else if(b>a){
                  if((b-a)%2==0)
                  cout<<2<<endl;
                  else
                  cout<<1<<endl;

            }
            else
            cout<<0<<endl;
      }
      return 0;
}


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

            }
            else
            cout<<0<<endl;
      }
      return 0;
}


#include <iostream>
using namespace std;
int main() {
	int n;
	cin>>n;
	for (int i = 0; i < n; i++)
	{
		int a,b;
		cin>>a>>b;
		if (a-b==0) {
			cout<<0<<endl;
			continue;
		}
		if (a>b)
		{
			if ((a-b)%2==0)
				cout<<1<<endl;
			else
				cout<<2<<endl;
		}
		else
		{
			if ((b-a)%2==0)
				cout<<2<<endl;
			else
				cout<<1<<endl;
		}
	}
	return 0;
	}


#include <iostream>
using namespace std;
int main() {
	int n;
	cin>>n;
	for (int i = 0; i < n; i++)
	{
		int a,b;
		cin>>a>>b;
		if (a<b)
		{
			if (b%2==0)
			{
				cout<<2<<endl;
			}
			else
			{
				cout<<1<<endl;
			}
		}
		if (a>b)
		{
			if (a%2==0 && b%2==0)
			{
				cout<<1<<endl;
			}
			if (a%2!=0 && b%2!=0)
			{
				cout<<1<<endl;
			}
			if (a%2!=0 && b%2==0)
			{
				cout<<2<<endl;
			}
		}
		if (a==b)
		{
			cout<<0<<endl;
		}
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <initializer_list>
#include <tuple>
#include <stack>
#include <iomanip>

using namespace std;

int main(){
    int k;
    cin >> k;
    for(int i = 0; i < k; ++i){
int a,b;cin >> a >> b;
if(a == b){
 cout << 0 <<endl;
continue;
}else if(a < b){
 if((a % 2) && (b % 2) || !(a % 2) && !(b % 2)){
     cout << 2 << endl;
 }else  cout << 1 << endl;
}else if ( a > b){
    if((a % 2) && (b % 2) || !(a % 2) && !(b % 2)){
        cout << 1 << endl;
    }else cout<< 2 << endl;
}
    }
 return 0;

}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <initializer_list>
#include <tuple>
#include <stack>
#include <iomanip>

using namespace std;

int main(){
    int k;
    cin >> k;
    for(int i = 0; i < k; ++i){
int a,b;cin >> a >> b;
if(a == b){
 cout << 0 <<endl;
continue;
}else if(a < b){
 if((a % 2) && (b % 2) || !(a % 2) && !(b & a)){
     cout << 2 << endl;
 }else  cout << 1 << endl;
}else if ( a > b){
    if((a % 2) && (b % 2) || !(a % 2) && !(b & a)){
        cout << 1 << endl;
    }else cout<< 2 << endl;
}
    }
 return 0;

}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <initializer_list>
#include <tuple>
#include <stack>
#include <iomanip>

using namespace std;

int main(){
    int k;
    cin >> k;
    for(int i = 0; i < k; ++i){
int a,b;cin >> a >> b;
if(a == b){
 cout << 0 <<endl;
continue;
}else if(a < b){
 if((a % 2) && (b % 2) || !(a % 2) && !(b & a)){
     cout << 2 << endl;
 }else  cout << 1 << endl;
}else if ( a > 2){
    if((a % 2) && (b % 2) || !(a % 2) && !(b & a)){
        cout << 1 << endl;
    }else cout<< 2 << endl;
}
    }
 return 0;

}


#include<bits/stdc++.h>
using namespace std;
main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b,res;
        cin>>a>>b;
        if(a>b)
        {
            if((a-b)%2==0)
               res=1;
            else
                res=2;
        }
        else if(a<b)
        {
            if((b-a)%2==0)
               res=1;
            else
                res=2;
        }
        else
          res=0;
        if(t>1)
          cout<<res<<" ";
        else
          cout<<res;

    }
}


#include<iostream>
using namespace std;
main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b,res;
        cin>>a>>b;
        if(a>b)
        {
            if((a-b)%2==0)
               res=1;
            else
                res=2;
        }
        else if(a<b)
        {
            if((b-a)%2==0)
               res=1;
            else
                res=2;
        }
        else
          res=0;
        if(t>1)
          cout<<res<<" ";
        else
          cout<<res;

    }
}


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b,res;
        cin>>a>>b;
        if(a>b)
        {
            if((a-b)%2==0)
               res=1;
            else
                res=2;
        }
        else if(a<b)
        {
            if((b-a)%2==0)
               res=2;
            else
                res=1;
        }
        else
          res=0;
        if(t>1)
          cout<<res<<" ";
        else
          cout<<res;

    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b,res;
        cin>>a>>b;
        if(a>b)
        {
            if((a-b)%2==0)
               res=1;
            else
                res=2;
        }
        else if(a<b)
        {
            if((b-a)%2==0)
               res=1;
            else
                res=2;
        }
        else
          res=0;
        if(t>1)
          cout<<res<<" ";
        else
          cout<<res;

    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b,res;
        cin>>a>>b;
        if(a>b)
        {
            if((a-b)%2==0)
               res=1;
            else
                res=2;
        }
        else if(a<b)
        {
            if((b-a)%2==0)
               res=2;
            else
                res=1;
        }
        else
          res=0;
        if(t>0)
          cout<<res<<" ";
        else
          cout<<res;

    }
    return 0;
}


#include<iostream>

using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        int diff = a-b;
        if(a==b){
            cout<<"1"<<endl;
        }
        else if(a>b && diff%2==0){
            cout<<"1"<<endl;
        }
        else if(a<b && diff%2!=0){
            cout<<"1"<<endl;
        }
        else{
            cout<<"2"<<endl;
        }
    }

    return 0;
}


#include<iostream>

using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        int diff = a-b;
        if(a==b){
            cout<<"0"<<endl;
        }
        else if(a>b && diff%2==0){
            cout<<"1"<<endl;
        }
        else if(a<b && diff%2!=0){
            cout<<"1"<<endl;
        }
        else{
            cout<<"2"<<endl;
        }
    }

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read(){
	int f=1,res=0;char c=getchar();
	while(c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){res=res*10+c-'0',c=getchar();}
	return f*res;
}
int t,a,b;
int main(){
	t=read();
	while(t--){
		a=read();b=read();
		if(a==b)
			cout<<"0"<<endl;
		else if(a%2==0&&b%2==0||a%2==1&&b%2==1){
			if(a<b) cout<<"2"<<endl;
			else cout<<"1"<<endl;
		}
		else cout<<"2"<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read(){
	int f=1,res=0;char c=getchar();
	while(c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){res=res*10+c-'0',c=getchar();}
	return f*res;
}
int t,a,b;
int main(){
	t=read();
	while(t--){
		a=read();b=read();
		if(a==b)
			cout<<"0"<<endl;
		else if(a%2==0&&b%2==0||a%2==1&&b%2==1){
			if(a<b) cout<<"2"<<endl;
			else cout<<"1"<<endl;
		}
		else {
			if(a<b) cout<<"1"<<endl;
			else cout<<"2"<<endl;
		}
	}
	return 0;
}


#include<iostream>
#include<string>
#include<sstream>
using namespace std;

int main(){

	int t,a,b,move;

	cin>>t;

	while(t--){

		move = 0;

		cin>>a>>b;

		if(b > a){
			if((b-a)%2 != 0)
				move++;
			else
				move = 2;
		}
		else
			if(a > b){
				if((a-b)%2 == 0)
					move++;
				else
					move+=2;
			}

		cout<<move<<endl;

	}

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>

using namespace std;

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

	for (int I = 0; I < t; I++)
	{
		int a, b;
		cin >> a >> b;

		if (a == b)
		{
			cout << '0';
			continue;
		}

		if (b > a && (b - a) % 2 != 0)
		{
			cout << '1';
			continue;
		}

		if (b > a && (b - a) % 2 == 0)
		{
			cout << '2';
			continue;
		}

		if (b < a && (b - a) % 2 != 0)
		{
			cout << '2';
			continue;
		}

		if (b < a && (b - a) % 2 == 0)
		{
			cout << '1';
			continue;
		}
	}

	getchar();
	getchar();
	getchar();
	getchar();
	getchar();
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>

using namespace std;

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

	for (int I = 0; I < t; I++)
	{
		int a, b;
		cin >> a >> b;

		if (a == b)
		{
			cout << '0' << endl;
			continue;
		}

		if (b > a && (b - a) % 2 != 0)
		{
			cout << '1' << endl;
			continue;
		}

		if (b > a && (b - a) % 2 == 0)
		{
			cout << '2' << endl;
			continue;
		}

		if (b < a && (b - a) % 2 != 0)
		{
			cout << '2' << endl;
			continue;
		}

		if (b < a && (b - a) % 2 == 0)
		{
			cout << '1' << endl;
			continue;
		}
	}

	getchar();
	getchar();
	getchar();
	getchar();
	getchar();
	return 0;
}


#include <iostream>
#include <cstring>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <deque>
#include <string>
using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int l, r;
		cin >> l >> r;
		if (l == r) {
			cout << 0 << "\n";
		}
		else if ((l % 2 != r % 2 && l < r) || (l % 2 == r % 2 && l > r)) {
			cout << 1 << "\n";
		}
		else {
			cout << 2 << "\n";
		}
	}
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int a,b,temp;
		cin>>a>>b;
		temp=b-a;
		if(temp==0)
		{
			cout<<0<<endl;
		}
		else if(temp>0)
		{
			if(temp%2==1)
			{
				cout<<1<<endl;
			}
			else
			{
				cout<<2<<endl;
			}
		}
		else if(temp<0)
		{
			if((-temp)%2==0)
			{
				cout<<1<<endl;
			}
			else
			{
				cout<<2<<endl;
			}
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
using  namespace  std;
const int M = 2e5 + 10;
int n;

int main()
{
	int t;
	int a, b;
	scanf("%d", &t);
	while (t--)
	{
		scanf("%d %d", &a, &b);
		int p = a - b;
		if (p == 0)
			printf("0\n");
		else if (p < 0)
		{
			if (p % 2)
				printf("1\n");
			else
				printf("2\n");
		}
		else
		{
			p = -p;
			if (p % 2)
				printf("2\n");
			else
				printf("1\n");
		}
	}
	return 0;
}


#include <iostream>
#include <cmath>

using namespace std;

int main()
{

    int t;
    long a,b;

    cin >> t;

    for (int j = 0; j<t; ++j) {
        cin >> a >> b;
        if (((a < b) && ((b-a)% 2 == 0)) || ((a>b) && ((a-b) % 2 != 0))) cout << "2";
        else {
            if (((a < b) && ((b-a)% 2 != 0)) || ((a>b) && ((a-b) % 2 == 0))) cout << "1";
            else cout << "0";
        }
        cout << endl;
    }

    return 0;
}


#include <iostream>
using namespace std;

int main()
{

int t,a,b,c;
cin>>t;

for(int i=0;i<t;i++)
{
  cin>>a>>b;
  if (a<b)
  {
    c=b-a;
    if(c%2==0)cout<<2<<endl;
    else cout<<1<<endl;

  }

  else if (a==b)cout<<0<<endl;

  else if(a>b)
  {
    c=a-b;
    if(c%2==0)cout<<1<<endl;
    else cout<<2<<endl;

  }

}

return 0;}


#include <iostream>
using namespace std;

int main()
{

int t,a,b,c;
cin>>t;

for(int i=0;i<t;i++)
{
  cin>>a>>b;
  if (a<b)
  cout<<b-a<<endl;
  else if (a==b)
  cout<<0<<endl;
  else if(a>b)
  {
    c=a-b;
    a-=c;
    cout<<((b-a)+1)<<endl;
  }

}

return 0;}


#include <iostream>
using namespace std;

int main()
{
int x,y,z,t;
cin>>t;
for (i=0;i<t;i++)
{
    cin>>x>>y;
    z=x-y;
    if (z<0) z*=-1
    if (z==0) cout<<z<<endl;
    if (z%2==0)cout<<1<<endl;
    if (z==1)cout<<1<<endl;
    if(z%2!=1)cout<<2<<endl;
}

return 0
}


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    long a,b;
    while(t--)
    {
        cin>>a>>b;
        if(a>b)
        {
            if((a-b)%2==0)
            cout<<"1"<<endl;
            else
            cout<<"2"<<endl;
        }
        else if(a<b)
        {
            if((b-a)%2!=0)
            cout<<"1"<<endl;
            else
            cout<<"2"<<endl;
        }
        else
        {
            cout<<"0"<<endl;
        }
    }
}


#include<iostream>
#include<cmath>
using namespace std;
int a,b,t;
int main()
{
    cin >> t;
    while ( t--)
    {
        cin >> a >> b;
        int x = a%2,y=b%2;
        if ( a == b ) cout << 0 << endl;
        else if ( a > b  && x == y ) cout << 1 << endl;
        else if ( a > b && x != y ) cout << 2 << endl;
        else if ( a < b && x != y) cout << 1 << endl;
        else cout << 2 << endl;
    }
}


#include<iostream>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<vector>
using namespace std;
int main()
{
	vector<int> Ans;
	int t, a, b, x, y, X1, X2, Y1, Y2, i, j, input;
	cin >> t;
	for (i = 0; i < t; i++)
	{
		cin >> a >> b;
		if (a == b)
			Ans.push_back(0);
		else if (b < a)
		{
			if ((a - b) % 2 == 0)
				Ans.push_back(1);
			else
				Ans.push_back(2);
		}
		else
		{
			if ((b - a) % 2 == 0)
				Ans.push_back(2);
			else
				Ans.push_back(1);
		}
	}
	for (i = 0; i < t; i++)
		cout << Ans[i] << endl;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int a,b,ans;
		scanf("%d %d",&a,&b);
		if(a>b&&(a%2)!=(b%2))
			ans=2;
		else if(a>b)
			ans=1;
		else if(a==b)
			ans=0;
		else if(a<b&&(a%2)==(b%2))
			ans=2;
		else
			ans=1;
		printf("%d\n",ans);
	}
	return 0;
}


#include<stdio.h>
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int a,b;
		scanf("%d%d",&a,&b);
		if(a==b)printf("0\n");
		else if(a>b){
			if((a-b)%2==0)printf("1\n");
			else printf("2\n");
		}
		else {
			if((a-b)%2)printf("1\n");
			else printf("2\n");
		}
	}
}


#include<stdio.h>
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int a,b;
		scanf("%d%d",&a,&b);
		if(a==b)printf("0\n");
		else if(a>b){
			if((a-b)%2==0)printf("1\n");
			else printf("2\n");
		}
		else {
			if((a-b)%2==1)printf("1\n");
			else printf("2\n");
		}
	}
}


#include <stdio.h>

using namespace std;

int main()
{

	int t;
	scanf_s("%d", &t);
	int a;
	int b;
	for (int i = 0; i < t; i++)
	{
		scanf_s("%d", &a);
		scanf_s("%d", &b);
		if (a == b)
		{
			printf("0");
		}
		else if ((a - b) % 2 == -1 || (a > b && (a - b) % 2 == 0))
		{
			printf("1");
		}
		else
		{
			printf("2");
		}
		printf("\n");
	}

	return 0;
}


#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
using namespace std;
int main(){

    int t;
    cin>>t;
    int a[100][100];
    int test;
    for(int i=0;i<t;i++){
        for(int j=0;j<2;j++){
            cin>>a[i][j];
        }
    }

      for(int i=0;i<t;i++){
        for(int j=0;j<2;j++){
            if(j==1){
                test=a[i][1]-a[i][0];
                if(test<=0){test=test*(-1);}

                if(a[i][1]==a[i][0]){cout<<0<<endl;}
                else if((test%2==0) && (a[i][0]>a[i][1])){cout<<1<<endl;}
                else if((test%2==1) && (a[i][0]>a[i][1])){cout<<2<<endl;}
                else if((test%2==0) && (a[i][0]<a[i][1])){cout<<2<<endl;}
                else if((test%2==1) && (a[i][0]<a[i][1])){cout<<1<<endl;}
                else{cout<<1;}
                }
        }
    }

    return 0;}


#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
using namespace std;
int main(){

    int t;
    cin>>t;
    int x=1;int y=2;
    int a[100][100];
    int test;
    for(int i=0;i<t;i++){
        for(int j=0;j<2;j++){
            cin>>a[i][j];
        }
    }

      for(int i=0;i<t;i++){
        for(int j=0;j<2;j++){
            if(j==1){
                test=a[i][1]-a[i][0];
                test=abs(test);
                if(a[i][1]==a[i][0]){cout<<0<<endl;}
                else if((test%2==0) && (a[i][0]>a[i][1])){cout<<1<<endl;}
                else if((test%2==1) && (a[i][0]>a[i][1])){cout<<2<<endl;}
                else if((test%2==0) && (a[i][0]<a[i][1])){cout<<2<<endl;}
                else if((test%2==1) && (a[i][0]<a[i][1])){cout<<1<<endl;}
                }
        }
    }

    return 0;}


#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
using namespace std;
int main(){

    int t;
    cin>>t;
    int x=1;int y=2;
    int a[100][100];
    int test;
    for(int i=0;i<t;i++){
        for(int j=0;j<2;j++){
            cin>>a[i][j];
        }
    }

      for(int i=0;i<t;i++){
        for(int j=0;j<2;j++){
            if(j==1){
                test=a[i][1]-a[i][0];
                test=abs(test);
                if((test>=3 && test%2==1) || test==2){cout<<2<<endl;}
                else if(a[i][0]==a[i][1]){cout<<0<<endl;}
                else{cout<<1<<endl;}
                }
        }
    }

    return 0;}


#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
using namespace std;
int main(){

    long long t;
    cin>>t;
    long long a[10000][2];
    long long test;
    for(int i=0;i<t;i++){
        for(int j=0;j<2;j++){
            cin>>a[i][j];
        }
    }

      for(int i=0;i<t;i++){
        for(int j=0;j<2;j++){
            if(j==1){
                test=a[i][1]-a[i][0];
                if(test<=0){test=test*(-1);}

                if(a[i][1]==a[i][0]){cout<<0<<endl;}
                else if((test%2==0) && (a[i][0]>a[i][1])){cout<<1<<endl;}
                else if((test%2==1) && (a[i][0]>a[i][1])){cout<<2<<endl;}
                else if((test%2==0) && (a[i][0]<a[i][1])){cout<<2<<endl;}
                else if((test%2==1) && (a[i][0]<a[i][1])){cout<<1<<endl;}
                else{cout<<1;}
                }
        }
    }

    return 0;}


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

#define iloop for(int i=0; i<n; i++){

void main(){
	long t, a, b, x, y, Left, Right, Up, Down;
	cin>>t;
	for(int i=0; i<t; i++){
		cin>>a>>b;
		if (a==b)
			cout<<0<<endl;
		else if (a>b){
			if ( (a - b) % 2 == 0)
				cout<<1<<endl;
			else
				cout<<2<<endl;
		}
		else{
			if ( (b - a) % 2 == 1)
				cout<<1<<endl;
			else
				cout<<2<<endl;
		}
	}
}


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

int main() {
	int number, a, b;
	cin >> number;
	for (int i = 0; i < number; i++) {
		cin >> a >> b;
		if(a < b) {
			if(((b - a) % 2)== 1) {
				cout << 1 << endl;
			} else if((b-a) % 2 == 0) {
				cout << 2 << endl;
			}
		} else if(a > b) {
			if((a-b) % 2 == 1) {
				cout << 2 << endl;
			} else if((a-b) % 2 == 0) {
				cout << 1 << endl;
			}
		} else {
			cout << 0;
		}
	}
}


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

int main() {
	int number, a, b;
	cin >> number;
	for (int i = 0; i < number; i++) {
		cin >> a >> b;
		if(a < b) {
			if(((b - a) % 2)== 1) {
				cout << 1 << endl;
			} else if((b-a) % 2 == 0) {
				cout << 2 << endl;
			}
		} else if(a > b) {
			if((a-b) % 2 == 1) {
				cout << 2 << endl;
			} else if((a-b) % 2 == 0) {
				cout << 1 << endl;
			}
		} else {
			cout << 0 << endl;
		}
	}
}


#include <iostream>

using namespace std;
bool isOdd(int x)
{
    return x%2 == 1;
}

int getMenimunm(int a,int b)
{
    if(a==b)
        return 0;
    if(a<b)
    {
        if(isOdd(a) && isOdd(b))
        {

              return 2;

        }else if(isOdd(a) && !isOdd(b))
        {
            return 1;
        }else if(!isOdd(a) && isOdd(b))
        {
          return 1;
        }else
        {

              return 2;

        }
    }else
    {
          if(isOdd(a) && isOdd(b))
          {
              return 1;
          }else if (!isOdd(b) && isOdd(a))
          {
              return 2;
          }else if (isOdd(b) && !isOdd(a))
          {
              return 2;
          }else
             return 1;
    }
}

int main()
{
    int t;
    cin>>t;
    for(int i=1;i<=t;i++)
    {
        int a,b;
        cin>>a>>b;
        cout << getMenimunm(a,b)<<endl;
    }
    return 0;
}


#include <iostream>

using namespace std;
bool isOdd(int x)
{
    return x%2 == 1;
}

int getMenimunm(int a,int b)
{
    if(a==b)
        return 0;
    if(a<b)
    {
        if(isOdd(a) && isOdd(b))
        {
            if((b-a) == 2)
          {
              return 2;
          }else
              return (b-a)/2;
        }else if(isOdd(a) && !isOdd(b))
        {
            return 1;
        }else if(!isOdd(a) && isOdd(b))
        {
          return 1;
        }else
        {
          if((b-a) == 2)
          {
              return 2;
          }else
              return (b-a)/2;
        }
    }else
    {
          if(isOdd(a) && isOdd(b))
          {
              return 1;
          }else if (!isOdd(b) && isOdd(a))
          {
              return 2;
          }else if (isOdd(b) && !isOdd(a))
          {
              return 2;
          }else
             return 1;
    }
}

int main()
{
    int t;
    cin>>t;
    for(int i=1;i<=t;i++)
    {
        int a,b;
        cin>>a>>b;
        cout << getMenimunm(a,b)<<endl;
    }
    return 0;
}


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

using namespace std;

int main()
{
	int n,i,j,k;
	pair<int,int>  a[100];

	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i].first>>a[i].second;

	sort(a,a+n);

	for(i=0;i<n;i++)
	{
		k=a[0].first;
		cout<<k<<" ";

        for(j=1;j<n;j++)
        	if(a[j].first==k)  a[j].first++;

        a[0]=a[n-1];

        n--;
        i--;
        sort(a,a+n);
	}

	return 0;
}


#include <stdio.h>
#include <sstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cassert>
#include <string.h>
using namespace std;
#pragma comment(linker, "/STACK:20000000")

typedef vector<int> VI;
#define sz(a) int((a).size())
#define All(c) (c).begin(),(c).end()
#define Rep(i,n) for(int i=0;i<(int)n;i++)
#define For(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define Ford(i,a,b) for(int i=(int)a;i>=(int)b;i--)

#define Fill(a,b) memset(a,b,sizeof(a))

string problem_name = "kitchen";

void init(){
    freopen((problem_name+".in").c_str(),"rt",stdin);
    freopen((problem_name+".out").c_str(),"wt",stdout);
}

int n;
pair< pair<int,int>, int > q[105];
int r[105];

bool cmp(pair< pair<int,int>, int > a, pair< pair<int,int>, int > b){
    if(a.first.second-a.first.first!=b.first.second-b.first.first)
        return a.first.second-a.first.first<b.first.second-b.first.first;
    return a<b;
}

int main(){

    cin>>n;

    Rep(i,n){
        cin>>q[i].first.first>>q[i].first.second;
        q[i].second=i;
    }

    sort(q,q+n,cmp);

    int p=0;

    Rep(i,n){
        p = q[i].first.first;
        bool ok=0;
        while(!ok){
            ok=1;
            Rep(i,n)
                if(r[i]==p){
                    ok=0;
                    break;
                }
            if(!ok) p++;
        }
        r[q[i].second]=p;
        //if(p>q[i].first.second) while(1);
    }

    Rep(i,n) cout<<r[i]<<" ";

    return 0;
}


#include <stdio.h>
#include <sstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cassert>
#include <string.h>
using namespace std;
#pragma comment(linker, "/STACK:20000000")

typedef vector<int> VI;
#define sz(a) int((a).size())
#define All(c) (c).begin(),(c).end()
#define Rep(i,n) for(int i=0;i<(int)n;i++)
#define For(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define Ford(i,a,b) for(int i=(int)a;i>=(int)b;i--)

#define Fill(a,b) memset(a,b,sizeof(a))

string problem_name = "kitchen";

void init(){
    freopen((problem_name+".in").c_str(),"rt",stdin);
    freopen((problem_name+".out").c_str(),"wt",stdout);
}

int n;
pair< pair<int,int>, int > q[105];
int r[105];

bool cmp(pair< pair<int,int>, int > a, pair< pair<int,int>, int > b){
    return a.first.second<b.first.second;
}

int main(){

    cin>>n;

    Rep(i,n){
        cin>>q[i].first.first>>q[i].first.second;
        q[i].second=i;
    }

    sort(q,q+n,cmp);

    int p=0;

    Rep(i,n){
        p = q[i].first.first;
        bool ok=0;
        while(!ok){
            ok=1;
            Rep(i,n)
                if(r[i]==p){
                    ok=0;
                    break;
                }
            if(!ok) p++;
        }
        r[q[i].second]=p;
    }

    Rep(i,n) cout<<r[i]<<" ";

    return 0;
}


#include <stdio.h>
#include <sstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cassert>
#include <string.h>
using namespace std;
#pragma comment(linker, "/STACK:20000000")

typedef vector<int> VI;
#define sz(a) int((a).size())
#define All(c) (c).begin(),(c).end()
#define Rep(i,n) for(int i=0;i<(int)n;i++)
#define For(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define Ford(i,a,b) for(int i=(int)a;i>=(int)b;i--)

#define Fill(a,b) memset(a,b,sizeof(a))

string problem_name = "kitchen";

void init(){
    freopen((problem_name+".in").c_str(),"rt",stdin);
    freopen((problem_name+".out").c_str(),"wt",stdout);
}

int n;
pair< pair<int,int>, int > q[105];
int r[105];
int main(){

    cin>>n;

    Rep(i,n){
        cin>>q[i].first.second>>q[i].first.first;
        q[i].second=i;
    }

    sort(q,q+n);

    int p=0;

    Rep(i,n){
        p=max(p+1,q[i].first.second);
        if(p>q[i].first.first) while(1);
        r[q[i].second]=p;
    }

    Rep(i,n) cout<<r[i]<<" ";

    return 0;
}


#include <stdio.h>
#include <sstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cassert>
#include <string.h>
using namespace std;
#pragma comment(linker, "/STACK:20000000")

typedef vector<int> VI;
#define sz(a) int((a).size())
#define All(c) (c).begin(),(c).end()
#define Rep(i,n) for(int i=0;i<(int)n;i++)
#define For(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define Ford(i,a,b) for(int i=(int)a;i>=(int)b;i--)

#define Fill(a,b) memset(a,b,sizeof(a))

string problem_name = "kitchen";

void init(){
    freopen((problem_name+".in").c_str(),"rt",stdin);
    freopen((problem_name+".out").c_str(),"wt",stdout);
}

int n;
pair< pair<int,int>, int > q[105];
int r[105];
int main(){

    cin>>n;

    Rep(i,n){
        cin>>q[i].first.first>>q[i].first.second;
        q[i].second=i;
    }

    sort(q,q+n);

    int p=0;

    Rep(i,n){
        p=max(p+1,q[i].first.first);
        if(p>q[i].first.second) while(1);
        r[q[i].second]=p;
    }

    Rep(i,n) cout<<r[i]<<" ";

    return 0;
}


#include <stdio.h>
#include <sstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cassert>
#include <string.h>
using namespace std;
#pragma comment(linker, "/STACK:20000000")

typedef vector<int> VI;
#define sz(a) int((a).size())
#define All(c) (c).begin(),(c).end()
#define Rep(i,n) for(int i=0;i<(int)n;i++)
#define For(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define Ford(i,a,b) for(int i=(int)a;i>=(int)b;i--)

#define Fill(a,b) memset(a,b,sizeof(a))

string problem_name = "kitchen";

void init(){
    freopen((problem_name+".in").c_str(),"rt",stdin);
    freopen((problem_name+".out").c_str(),"wt",stdout);
}

int n;
pair< pair<int,int>, int > q[105];
int r[105];
int main(){

    cin>>n;

    Rep(i,n){
        cin>>q[i].first.second>>q[i].first.first;
        q[i].second=i;
    }

    sort(q,q+n);

    int p=0;

    Rep(i,n){
        p=max(p+1,q[i].first.second);
        //if(p>q[i].first.first) while(1);
        r[q[i].second]=p;
    }

    Rep(i,n) cout<<r[i]<<" ";

    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

struct day
{
	int l, r, num, ans;

	bool operator <(day other)
	{ return r < other.r; }
} a[100];

bool compare(day a, day b)
{ return a.num < b.num; }

int n;
bool b[10000010];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].l >> a[i].r;
		a[i].num = i+1;
	}
	sort(a, a + n);
	for (int i = 0; i < n; i++)
	{
		int j = a[i].l;
		while (b[j])
			j++;
		b[j] = true;
		a[i].ans = j;
	}
	sort(a, a + n, compare);
	for (int i = 0; i < n; i++)
		cout << a[i].ans << " ";
	return 0;
}


#pragma comment(linker, "/STACK:16777216")
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <cassert>
#include <functional>
#include <utility>

#define forn( i,n ) for ( int i=0; i<(int)(n); i++ )

using namespace std;

int n,k=0;
vector<pair<pair<int,int>,int>> x;
vector<pair<int,int>> an;
set <int > ans;
bool comp(pair<int,int> x1,pair<int,int> x2)
{
	return (x1.second < x2.second);
}
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	cin >> n;
	x.resize(n);
	forn(i,n)
	{
		int y;
		cin >> x[i].first.second >> y;
		x[i].first.first = y - x[i].first.second;
		x[i].second = i;
	}
	sort(x.begin(),x.end());
	forn(i,n)
	{
		for (int j=x[i].first.second;j<=x[i].first.second+x[i].first.first;j++)
			if (!ans.count(j))
			{
				an.push_back(make_pair(j,x[i].second));
				ans.insert(j);
				break;
			}
	}
	sort(an.begin(),an.end(),comp);
	forn(i,an.size())
		cout << an[i].first << " ";
	return 0;
}


#pragma comment(linker, "/STACK:16777216")
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <cassert>
#include <functional>
#include <utility>

#define forn( i,n ) for ( int i=0; i<(int)(n); i++ )

using namespace std;

int n,k=0;
vector<pair<int,int>> x;
set <int > ans;
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	cin >> n;
	x.resize(n);
	forn(i,n)
		cin >> x[i].first >> x[i].second;
	sort(x.begin(),x.end());
	forn(i,n)
	{
		for (int j=x[i].first;j<=x[i].second;j++)
			if (!ans.count(j))
			{
				cout << j << " ";
				ans.insert(j);
				break;
			}
	}
	return 0;
}


#pragma comment(linker, "/STACK:16777216")
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <cassert>
#include <functional>
#include <utility>

#define forn( i,n ) for ( int i=0; i<(int)(n); i++ )

using namespace std;

int n;
vector<pair<pair<int,int>,int>> x;
vector<pair<int,int>> an;
set <int > ans;
bool comp(pair<int,int> x1,pair<int,int> x2)
{
	return (x1.second < x2.second);
}
bool cmp(pair<pair<int,int>,int> x1,pair<pair<int,int>,int> x2)
{
	return (x1.first.second < x2.first.second);
}
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	cin >> n;
	x.resize(n);
	forn(i,n)
	{
		int y;
		cin >> x[i].first.first >> x[i].first.second;
		x[i].second = i;
	}
	sort(x.begin(),x.end(),cmp);
	forn(i,n)
	{
		for (int j=x[i].first.first;j<=x[i].first.second;j++)
			if (!ans.count(j))
			{
				an.push_back(make_pair(j,x[i].second));
				ans.insert(j);
				break;
			}
	}
	sort(an.begin(),an.end(),comp);
	forn(i,an.size())
		cout << an[i].first << " ";
	return 0;
}


//D
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;
struct point{
	int x;
	int y;
	int number;
	int point_need;
};

vector<point> v;

bool pred(point &p1, point &p2){
	return abs(p1.x - p1.y ) < abs(p2.x - p2.y) ? true:  abs(p1.x - p1.y ) == abs(p2.x - p2.y) ? p1.x < p2.y : false;
}
bool pred2(point &p1, point &p2){
	return p1.number < p2.number;
}
int main(){
	//freopen("input.txt", "r", stdin);
	int n;
	cin >> n;
	point p;
	for (int i = 0 ; i < n; ++i){
		cin >> p.x >> p.y;
		p.number = i;
		v.push_back(p);
	}
	sort(v.begin(), v.end(), &pred);
	int min = 0;//v[0].x;
	set<int> s;
	for (int i = 0 ; i < n; ++i){
		bool b = true;
		for ( int j = v[i].x; j <= v[i].y; ++j){
			if(s.find(j) == s.end()) {
				b= false;
				s.insert(j);
				v[i].point_need = j;
				break;
			}
		}
		if(b)
			cout << "error";
	}

	sort(v.begin(), v.end(), &pred2);

	for ( vector<point>::iterator j = v.begin(); j != v.end(); ++j){
			cout << j->point_need << " ";
		}
	cout<< endl;
	return 0;
}


#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;
struct point{
	int x;
	int y;
};

vector<point> v;

bool pred(point &p1, point &p2){
	return abs(p1.x - p1.y ) < abs(p2.x - p2.y);
}
int main(){
	//freopen("input.txt", "r", stdin);
	int n;
	cin >> n;
	point p;
	for (int i = 0 ; i < n; ++i){
		cin >> p.x >> p.y;
		v.push_back(p);
	}
	sort(v.begin(), v.end(), &pred);
	int min = 0;//v[0].x;
	set<int> s;
	for (int i = 0 ; i < n; ++i){
		bool b = true;
		for ( int j = v[i].x; j <= v[i].y; ++j){
			if(s.find(j) == s.end()) {
				b= false;
				s.insert(j);
				break;
			}
		}
		if(b)
			cout << "error";
	}
	for ( set<int>::iterator j = s.begin(); j != s.end(); ++j){
			cout << *j << " ";
		}
}


//D
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;
struct point{
	int x;
	int y;
	int number;
	int point_need;
	int minus;
	int len;
};

vector<point> v;
set<int> s;

bool pred(point &p1, point &p2){
	return p1.len < p2.len ? true:  p1.len == p2.len ? p1.x < p2.x : false;
}
bool pred2(point &p1, point &p2){
	return p1.number < p2.number;
}
void sort_re(vector<point>::iterator begin, vector<point>::iterator end){
	for (vector<point>::iterator j = begin; j != end; ++j){
		if (s.find(j->x) != s.end())j->x ++;
		if (s.find(j->y) != s.end())j->y --;
		j->len = j->y - j-> x;
		for(set<int>::iterator it = s.begin(); it != s.end(); it++){
			if(j->x <= *it && *it <= j->y)
				j->len-=1;
		}
	}
	sort(begin, end, &pred);
}
int main(){
	//freopen("input.txt", "r", stdin);
	int n;
	cin >> n;
	point p;
	for (int i = 0 ; i < n; ++i){
		cin >> p.x >> p.y;

		p.len = p.y - p.x;
		p.number = i;
		v.push_back(p);
	}
	sort(v.begin(), v.end(), &pred);
	//int min = 0;//v[0].x;

	for (int i = 0 ; i < n; ++i){
		bool b = true;
		if ( v[i].x != v[i].y ){
			sort_re(v.begin() + i , v.end());
		}
		for ( int j = v[i].x; j <= v[i].y; ++j){
			if(s.find(j) == s.end()) {
				b = false;
				s.insert(j);
				v[i].point_need = j;
				break;
			}
		}
		if(b)
			cout << "error";
	}

	sort(v.begin(), v.end(), &pred2);

	for ( vector<point>::iterator j = v.begin(); j != v.end(); ++j){
			cout << j->point_need << " ";
		}
	cout<< endl;
	return 0;
}


//D
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;
struct point{
	int x;
	int y;
	int number;
	int point_need;
};

vector<point> v;

bool pred(point &p1, point &p2){
	return abs(p1.x - p1.y ) < abs(p2.x - p2.y) ? true:  abs(p1.x - p1.y ) == abs(p2.x - p2.y) ? p1.x < p2.y : false;
}
bool pred2(point &p1, point &p2){
	return p1.number < p2.number;
}
int main(){
	//freopen("input.txt", "r", stdin);
	int n;
	cin >> n;
	point p;
	for (int i = 0 ; i < n; ++i){
		cin >> p.x >> p.y;
		p.number = i;
		v.push_back(p);
	}
	sort(v.begin(), v.end(), &pred);
	int min = 0;//v[0].x;
	set<int> s;
	for (int i = 0 ; i < n; ++i){
		bool b = true;
		for ( int j = v[i].x; j <= v[i].y; ++j){
			if(s.find(j) == s.end()) {
				b= false;
				s.insert(j);
				v[i].point_need = j;
				break;
			}
		}
		if(b)
			cout << "error";
	}

	sort(v.begin(), v.end(), &pred2);

	for ( vector<point>::iterator j = v.begin(); j != v.end(); ++j){
			cout << j->point_need << " ";
		}
}


//D
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;
struct point{
    int x;
    int y;
    int number;
    int point_need;
};

vector<point> v;

bool pred(point &p1, point &p2){
    return abs(p1.x - p1.y ) < abs(p2.x - p2.y) ? true:  abs(p1.x - p1.y ) == abs(p2.x - p2.y) ? p1.x < p2.x : false;
}
bool pred2(point &p1, point &p2){
    return p1.number < p2.number;
}
int main(){
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    point p;
    for (int i = 0 ; i < n; ++i){
        cin >> p.x >> p.y;
        p.number = i;
        v.push_back(p);
    }
    sort(v.begin(), v.end(), &pred);
    int min = 0;//v[0].x;
    set<int> s;
    for (int i = 0 ; i < n; ++i){
        bool b = true;
        for ( int j = v[i].x; j <= v[i].y; ++j){
            if(s.find(j) == s.end()) {
                b= false;
                s.insert(j);
                v[i].point_need = j;
                break;
            }
        }
        if(b)
            cout << "error";
    }

    sort(v.begin(), v.end(), &pred2);

    for ( vector<point>::iterator j = v.begin(); j != v.end(); ++j){
            cout << j->point_need << " ";
        }
    cout<< endl;
    return 0;
}


//D
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;
struct point{
    int x;
    int y;
    int number;
    int point_need;
};

vector<point> v;

bool pred(point &p1, point &p2){
    return abs(p1.x - p1.y ) < abs(p2.x - p2.y) ? true:  abs(p1.x - p1.y ) == abs(p2.x - p2.y) ? p1.x < p2.y : false;
}
bool pred2(point &p1, point &p2){
    return p1.number < p2.number;
}
int main(){
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    point p;
    for (int i = 0 ; i < n; ++i){
        cin >> p.x >> p.y;
        p.number = i;
        v.push_back(p);
    }
    sort(v.begin(), v.end(), &pred);
    int min = 0;//v[0].x;
    set<int> s;
    for (int i = 0 ; i < n; ++i){
        bool b = true;
        for ( int j = v[i].x; j <= v[i].y; ++j){
            if(s.find(j) == s.end()) {
                b= false;
                s.insert(j);
                v[i].point_need = j;
                break;
            }
        }
        //if(b)
            //cout << "error";
    }

    sort(v.begin(), v.end(), &pred2);

    for ( vector<point>::iterator j = v.begin(); j != v.end(); ++j){
            cout << j->point_need << " ";
        }
    cout<< endl;
    return 0;
}


#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;
struct point{
	int x;
	int y;
	int number;
	int point_need;
};

vector<point> v;

bool pred(point &p1, point &p2){
	return abs(p1.x - p1.y ) < abs(p2.x - p2.y);
}
bool pred2(point &p1, point &p2){
	return p1.number < p2.number;
}
int main(){
	//freopen("input.txt", "r", stdin);
	int n;
	cin >> n;
	point p;
	for (int i = 0 ; i < n; ++i){
		cin >> p.x >> p.y;
		p.number = i;
		v.push_back(p);
	}
	sort(v.begin(), v.end(), &pred);
	int min = 0;//v[0].x;
	set<int> s;
	for (int i = 0 ; i < n; ++i){
		bool b = true;
		for ( int j = v[i].x; j <= v[i].y; ++j){
			if(s.find(j) == s.end()) {
				b= false;
				s.insert(j);
				v[i].point_need = j;
				break;
			}
		}
		if(b)
			cout << "error";
	}

	sort(v.begin(), v.end(), &pred2);

	for ( vector<point>::iterator j = v.begin(); j != v.end(); ++j){
			cout << j->point_need << " ";
		}
}


//D
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;
struct point{
	int x;
	int y;
	int number;
	int point_need;
	int minus;
	int len;
};

vector<point> v;
set<int> s;

bool pred(point &p1, point &p2){
	return p1.len < p2.len ? true:  p1.len == p2.len ? p1.x < p2.x : false;
}
bool pred2(point &p1, point &p2){
	return p1.number < p2.number;
}
void sort_re(vector<point>::iterator begin, vector<point>::iterator end){
	for (vector<point>::iterator j = begin; j != end; ++j){
		if (s.find(j->x) != s.end())j->x ++;
		if (s.find(j->y) != s.end())j->y --;
		j->len = j->y - j-> x;
		for(set<int>::iterator it = s.begin(); it != s.end(); it++){
			if(j->y <= *it && *it <= j->x)
				j->len-=1;
		}
	}
	sort(begin, end, &pred);
}
int main(){
	//freopen("input.txt", "r", stdin);
	int n;
	cin >> n;
	point p;
	for (int i = 0 ; i < n; ++i){
		cin >> p.x >> p.y;

		p.len = p.y - p.x;
		p.number = i;
		v.push_back(p);
	}
	sort(v.begin(), v.end(), &pred);
	//int min = 0;//v[0].x;

	for (int i = 0 ; i < n; ++i){
		bool b = true;
		if ( v[i].x != v[i].y ){
			sort_re(v.begin() + i , v.end());
		}
		for ( int j = v[i].x; j <= v[i].y; ++j){
			if(s.find(j) == s.end()) {
				b = false;
				s.insert(j);
				v[i].point_need = j;
				break;
			}
		}
		if(b)
			cout << "error";
	}

	sort(v.begin(), v.end(), &pred2);

	for ( vector<point>::iterator j = v.begin(); j != v.end(); ++j){
			cout << j->point_need << " ";
		}
	cout<< endl;
	return 0;
}


#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
struct point{
	int x;
	int y;
};

vector<point> v;

bool pred(point &p1, point &p2){
	return (p1.x < p2.x ? true : p1.y < p2.y);
}
int main(){
	//freopen("input.txt", "r", stdin);
	int n;
	cin >> n;
	point p;
	for (int i = 0 ; i < n; ++i){
		cin >> p.x >> p.y;
		v.push_back(p);
	}
	sort(v.begin(), v.end(), &pred);
	int min = 0;//v[0].x;
	for (int i = 0 ; i < n; ++i){
		if (min < v[i].x) min =v[i].x;
		if (min >= v[i].x && min <= v[i].y){
			cout << min << " ";
			min += 1;
		} else {
			cout << "ERROR";
			break;
		}
	}
}


//D
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;
struct point{
	int x;
	int y;
	int number;
	int point_need;
};

vector<point> v;
set<int> s;

bool pred(point &p1, point &p2){
	return abs(p1.x - p1.y ) < abs(p2.x - p2.y) ? true:  abs(p1.x - p1.y ) == abs(p2.x - p2.y) ? p1.x < p2.x : false;
}
bool pred2(point &p1, point &p2){
	return p1.number < p2.number;
}
void sort_re(vector<point>::iterator begin, vector<point>::iterator end){
	for (vector<point>::iterator j = begin; j != end; ++j){
		if (s.find(j->x) != s.end())j->x ++;
		if (s.find(j->y) != s.end())j->y --;
	}
	sort(begin, end, &pred);
}
int main(){
	//freopen("input.txt", "r", stdin);
	int n;
	cin >> n;
	point p;
	for (int i = 0 ; i < n; ++i){
		cin >> p.x >> p.y;
		p.number = i;
		v.push_back(p);
	}
	sort(v.begin(), v.end(), &pred);
	//int min = 0;//v[0].x;

	for (int i = 0 ; i < n; ++i){
		bool b = true;
		if ( v[i].x != v[i].y ){
			sort_re(v.begin() + i , v.end());
		}
		for ( int j = v[i].x; j <= v[i].y; ++j){
			if(s.find(j) == s.end()) {
				b = false;
				s.insert(j);
				v[i].point_need = j;
				break;
			}
		}
		if(b)
			cout << "error";
	}

	sort(v.begin(), v.end(), &pred2);

	for ( vector<point>::iterator j = v.begin(); j != v.end(); ++j){
			cout << j->point_need << " ";
		}
	cout<< endl;
	return 0;
}