#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
#define rep(start, n, c) for(((i)=(start));((i)<(n));((i)+=(c)))
#define MAX 100000
#define MAX_INT INT_MAX
int main() {
  int n, i, j = -1, k = -1, rated = 0, j_prev;
  scanf("%d", &n);
  int *arr1 = (int*)malloc(n * sizeof(int));
  int *arr2 = (int*)malloc(n * sizeof(int));
  for(i = 0;i < n;i++) {
    scanf("%d %d", &k, &j);
    arr1[i] = k;
    arr2[i] = j;
  }
  j_prev = arr1[0];
  for(i = 0;i < n;i++) {
    if(arr1[i] != arr2[i]) {
      printf("rated");
      return 0;
    }
  }
  for(i = 1;i < n;i++) {
    if(arr1[i] > j_prev) {
      printf("unrated");
      return 0;
    }
    j_prev = arr1[i];
  }
  printf("maybe");
  return 0;
}


#include <stdio.h>

int main()
{
    int n, x, y, z=4127, i, g=0;
    scanf("%d", &n);
    for(i=0; i<n; i++)
    {
      scanf("%d %d", &x, &y);
      if((x-y)!=0)return 0*printf("rated");
      if(g==0)
      {
        if(x>z)g++;
        z=x;
      }
    }
    if(g>0)printf("unrated");
    else printf("maybe");
    return 0;
}


#include <stdio.h>

int main()
{
    int n, x, y, z=4127, i, j=0, g=0;
    scanf("%d", &n);
    for(i=0; i<n; i++)
    {
      scanf("%d %d", &x, &y);
      if((x-y)!=0)j++;
      if(x>z)g++;
      z=x;
    }
    if(j>0)printf("rated");
    else
    {
        if(g>0)printf("unrated");
        else printf("maybe");
    }
}


#include <stdio.h>

int main()
{
    int n, x, y, z=4127, g=0;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
    {
      scanf("%d %d", &x, &y);
      if((x-y)!=0)return 0*printf("rated");
      if(g==0)
      {
        if(x>z)g++;
        z=x;
      }
    }
    if(g>0)printf("unrated");
    else printf("maybe");
    return 0;
}


#include <stdio.h>

int main()
{
    int n, x, y, z=4127, i, g=0;
    scanf("%d", &n);
    for(i=0; i<n; i++)
    {
      scanf("%d %d", &x, &y);
      if((x-y)!=0)return printf("rated");
      if(g==0)
      {
        if(x>z)g++;
        z=x;
      }
    }
    if(g>0)printf("unrated");
    else printf("maybe");
}


#include <stdio.h>

int main()
{
    int n, x, y, z=4127, i, g=0;
    scanf("%d", &n);
    for(i=0; i<n; i++)
    {
      scanf("%d %d", &x, &y);
      if((x-y)!=0)return 0*printf("rated");
      if(g==0)
      {
        if(x>z)g++;
        z=x;
      }
    }
    if(g>0)printf("unrated");
    else printf("maybe");
}


#include <stdio.h>
int is_sorted_desc(int *arr, int length) {
    for (int i=0; i<length-1; i++) {
        if (arr[i]<arr[i+1]) return 0;
    }
    return 1;
}
int main() {
    int len,i=0,keep=1;
    scanf("%d\n",&len);
    int final[len],origin[len];
    while (i<len && keep) {
        scanf("%d %d",&final[i],&origin[i]);
        if (final[i]!=origin[i]) {
            keep=0;
            printf("rated");
        }
        i++;
    }
    if (keep) {
        if (is_sorted_desc(final,len)) {
            printf("maybe");
        } else {
            printf("unrated");
        }
    }
    return 0;
}


#include<stdio.h>
int ini[1000],fin[1000];
main()
{
    int n,i,mark=0;
    scanf("%d", &n);
    for(i=0;i<n;i++)
    {
        scanf("%d %d", &ini[i],&fin[i]);
        if(ini[i]!=fin[i])
        {
            return !printf("rated");
        }
    }

}


#include<stdio.h>
int ini[1000],fin[1000];
main()
{
    int n,i,mark=0;
    scanf("%d", &n);
    for(i=0;i<n;i++)
    {
        scanf("%d %d", &ini[i],&fin[i]);
        if(ini[i]!=fin[i])
        {
            return !printf("rated");
        }
    }
    for(i=0;i<n-1;i++)
    {
        if(ini[i+1]>ini[i]) mark++;
    }
    if(mark) printf("unrated");
    else printf("maybe");

}


#include<stdio.h>
int ini[1000],fin[1000];
main()
{
    int n,i,mark=0;
    scanf("%d", &n);
    for(i=0;i<n;i++)
    {
        scanf("%d %d", &ini[i],&fin[i]);
        if(ini[i]!=fin[i])
        {
            return !printf("rated");
        }
    }
    for(i=0;i<n-1;i++)
    {
        if(ara[i+1]>ara[i]) mark++;
    }
    if(mark) printf("unrated");
    else printf("maybe");

}


#include <stdio.h>

void swap(int* a, int* b);

int findLarge(int a[], int low, int high);
void selectionSort(int a[], int low, int high);

int main(){
    int n,count=0;
    int before[1000] ={0};
    int after[1000] ={0};
    scanf("%d",&n);

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

    for(int i = 0;i<n;i++){
        if(before[i] == after[i]){
            count++;
        }
    }

    if(count < n){
        printf("rated");

    }
    else{
        selectionSort(before,0,n-1);
        count = 0;
        int k = 0;
        for(int i = n-1;i>=0;i--){
            if(before[i] == after[k]){
                count++;
                k++;
            }
        }

        if(count == n){
            printf("maybe");
        }
        else{
            printf("unrated");
        }
    }

}

void selectionSort(int a[], int low, int high){
	int large;
	if (low >= high)
		return;
	large = findLarge(a, low, high);
	selectionSort(a, low, large - 1);
}

int findLarge(int a[], int low, int high){
	while (1){
		while (low < high && a[high] >= a[low])
			low++;
		swap(&a[low++], &a[high]);
		if (low >= high)
			break;
	}
	return high;
}

void swap(int* a, int* b){
	 int temp = *a;
	 *a = *b;
	 *b = temp;
}


#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int main(void){
	int n, a, a0 = 4127, b, i;
	bool to_be_rated = true, unordered = false;

	scanf("%d", &n);

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

		if(to_be_rated){
			if(a!=b){
				printf("rated\n");
				to_be_rated = false;
			}else{
				if(a0 < a){
					unordered = true;
				}
			}

			a0 = a;
		}
	}

	if(to_be_rated){
		if(unordered){
			printf("unrated");
		}else{
			printf("maybe\n");
		}
	}

	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main(void){
	int n, a, a0, b, i, rated = 0;

	scanf("%d", &n);

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

		if(a!=b){
			printf("rated\n");
			return 0;
		}else{
			if(i>0)
				if(a0 < a){
					printf("unrated\n");
					return 0;
				}
		}

		a0 = a;
	}

	printf("maybe\n");

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int main(void){
	int n, a, a0, b, i;
	bool to_be_rated = true;

	scanf("%d", &n);

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

		if(to_be_rated){
			if(a!=b){
				printf("rated\n");
				to_be_rated = false;
			}else{
				if(i>0)
					if(a0 < a){
						printf("unrated\n");
						to_be_rated = false;
					}
			}

			a0 = a;
		}
	}

	if(to_be_rated){
		printf("maybe\n");
	}

	return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
    int n;
    scanf("%d\n",&n);
    int arr1[n];
    int arr2[n];
    int f=1;
    for(int i=0;i<n;i++){
    scanf("%d %d\n",&arr1[i],&arr2[i]);
      if(arr1[i]!=arr2[i])
      f=0;
    }
    int f2=0;
    for(int i=0;i<n;i++)
    {
       for(int j=i+1;j<n;j++)
       {
           if(arr1[j]>arr1[i])
           {
                    f2=1;
                    break;
           }
       }
    }
    if(f==0)
    printf("rated");
    else if(f==1&&f2==1)
    printf("unrated");
    else if(f==1&&f2==0)
    printf("maybe");
     return 0;
}


#include <stdio.h>

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

    int player[n][2];
    for(int i = 0; i < n; i++)
    {
        scanf("%d %d", &player[i][0], &player[i][1]);
    }

    int changed = 0;
    for(int i = 0; i < n; i++)
    {
        if(player[i][0] != player[i][1])
        {
            changed = 1;
            break;
        }
    }

    if(changed)
        printf("rated\n");
    else
    {
        int ascned = 1;
        for(int i = 0; i < n-1; i++)
        {
            if(player[i][0] < player[i+1][0])
            {
                ascned = 0;
                break;
            }
        }

        if(ascned)
            printf("maybe\n");
        else
            printf("unrated\n");
    }

}


#include<stdio.h>
int main()
{
    int n,i,j,temp,camp,sum=0,count=0;
    scanf("%d",&n);
    int a[n][2];

    for(i=0;i<n;i++)
    {
        for(j=0;j<2;j++)
            scanf("%d",&a[i][j]);
        if(a[i][0]!=a[i][1])
            count++;
    }
    if(count!=0)
    {
        printf("rated\n");
        return 0;
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<i;j++)
        {
            if(a[i][0]>a[j][0])
            {
                printf("unrated\n");
                return 0;
            }
        }
    }
    printf("maybe\n");
}


#include<stdio.h>
int main()
{
    int n,i,j,sum=0,count=0;
    scanf("%d",&n);
    int a[n][2];

    for(i=0;i<n;i++)
    {
        for(j=0;j<2;j++)
            scanf("%d",&a[i][j]);
        if(a[i][0]!=a[i][1])
            count++;
    }
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(a[i][0]==a[j][0])
            {
                sum++;
                i=n;
                break;
            }
        }
    }
    if(count!=0)
        printf("rated\n");
    else if(count==0&&sum==0)
        printf("unrated\n");
    else
        printf("maybe\n");
    return 0;
}


#include<stdio.h>
int main()
{
    int n,i,j,sum=0,count=0;
    scanf("%d",&n);
    int a[n][2];

    for(i=0;i<n;i++)
    {
        for(j=0;j<2;j++)
            scanf("%d",&a[i][j]);
        if(a[i][0]!=a[i][1])
            count++;
    }
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(a[i][0]==a[j][0])
            {
                sum++;
                i=n;
                break;
            }
        }
    }
    if(sum==0 && count!=0)
        printf("rated\n");
    else if(sum==0)
        printf("unrated\n");
    else
        printf("maybe\n");
    return 0;
}


#include<stdio.h>
int main()
{
    int n,i,j,sum=0,count=0;
    scanf("%d",&n);
    int a[n][2];

    for(i=0;i<n;i++)
    {
        for(j=0;j<2;j++)
            scanf("%d",&a[i][j]);
        if(a[i][0]!=a[i][1])
            count++;
    }
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(a[i][0]==a[j][0] && a[i][1]==a[j][1])
            {
                sum++;
                i=n;
                break;
            }
        }
    }
    if(count!=0 && sum==0)
        printf("rated\n");
    else if(sum!=0)
        printf("maybe\n");
    else
        printf("unrated\n");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
int array[1000][2],number,flag1=0,flag2=0,i,j;
scanf("%d",&number);
for(i=0;i<number;++i){
    for(j=0;j<2;++j){
        scanf("%d",&array[i][j]);
    }
}
for(i=0;i<number;++i){
        if(array[i][0]-array[i][1]!=0){
            flag1=1;
            flag2=1;
            break;
        }
}
if(flag1==1&&flag2==1){
    printf("rated");
    return 0;
}
else{
for(i=0;i<number;++i){
    for(j=i+1;j<number;++j){
        if(array[i][0]>=array[j][0]){
            flag1=1;
        }
        else{
            flag1=0;
            break;
        }
    }
}
if(flag1==0&&flag2==0){
    printf("unrated");
}
else{
    printf("maybe");
}
}

    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
int array[1000][2],number,flag1=0,flag2=0,i,j;
scanf("%d",&number);
for(i=0;i<number;++i){
    for(j=0;j<2;++j){
        scanf("%d",&array[i][j]);
    }
}
for(i=0;i<number;++i){
        if(array[i][0]-array[i][1]!=0){
            flag1=1;
            flag2=1;
            break;
        }
}
if(flag1==1&&flag2==1){
    printf("rated");
    return 0;
}
else{
for(i=0;i<number;++i){
    for(j=i+1;j<number;++j){
        if(array[i][0]>=array[j][0]){
            flag1=1;
        }
        else{
            flag1=0;
        }
    }
}
else if(flag1==0&&flag2==0){
    printf("unrated");
}
else{
    printf("maybe");
}
}

    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
int array[1000][2],number,flag1=0,flag2=0,i,j;
scanf("%d",&number);
for(i=0;i<number;++i){
    for(j=0;j<2;++j){
        scanf("%d",&array[i][j]);
    }
}
for(i=0;i<number;++i){
        if(array[i][0]-array[i][1]!=0){
            flag1=1;
            flag2=1;
            break;
        }
}
if(flag1==1&&flag2==1){
    printf("rated");
    return 0;
}
else{
for(i=0;i<number;++i){
        if(array[i][0]>=array[i+1][0]){
            flag1=1;
        }
        else if(i==number-1){
            break;
        }
        else{
            flag1=0;
            break;
        }
}
if(flag1==0&&flag2==0){
    printf("unrated");
}
else{
    printf("maybe");
}
}

    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
int array[1000][2],number,flag1=0,flag2=0,i,j;
scanf("%d",&number);
for(i=0;i<number;++i){
    for(j=0;j<2;++j){
        scanf("%d",&array[i][j]);
    }
}
for(i=0;i<number;++i){
        if(array[i][0]-array[i][1]!=0){
            flag1=1;
            flag2=1;
            break;
        }
}
if(flag1==1&&flag2==1){
    printf("rated");
    return 0;
}
else{
for(i=0;i<number;++i){
    for(j=i+1;j<number;++j){
        if(array[i][0]>=array[j][0]){
            flag1=1;
        }
        else{
            flag1=0;
        }
    }
}
if(flag1==0&&flag2==0){
    printf("unrated");
}
else{
    printf("maybe");
}
}

    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
int array[1000][2],number,flag1=0,flag2=0,i,j;
scanf("%d",&number);
for(i=0;i<number;++i){
    for(j=0;j<2;++j){
        scanf("%d",&array[i][j]);
    }
}
for(i=0;i<number;++i){
        if(array[i][0]-array[i][1]!=0){
            flag1=1;
            flag2=1;
            break;
        }
}
if(flag1==1&&flag2==1){
    printf("rated");
    return 0;
}
else{
for(i=0;i<number;++i){
        if(array[i][0]>=array[i+1][0]){
            flag1=1;
        }
        else{
            flag1=0;
            break;
        }
}
if(flag1==0&&flag2==0){
    printf("unrated");
}
else{
    printf("maybe");
}
}

    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
int array[1000][2],number,flag1=0,flag2=0,i,j;
scanf("%d",&number);
for(i=0;i<number;++i){
    for(j=0;j<2;++j){
        scanf("%d",&array[i][j]);
    }
}
for(i=0;i<number;++i){
        if(array[i][0]-array[i][1]!=0){
            flag1=1;
            flag2=1;
            break;
        }
}
for(i=0;i<number;++i){
    for(j=i+1;j<number;++j){
        if(array[i][0]>=array[j][0]){
            flag1=1;
        }
        else{
            flag1=0;
        }
    }
}
if(flag1==1&&flag2==1){
    printf("rated");
}
else if(flag1==0&&flag2==0){
    printf("unrated");
}
else{
    printf("maybe");
}

    return 0;
}


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

int main()
{
    int n;
    scanf("%d",&n);
    int a[n],b[n],i,c=0,d=0,h=0;
    for(i=0; i<n; i++)
        scanf("%d%d",&a[i],&b[i]);

    for(i=0; i<n-1; i++)
    {

        if(a[i]==b[i] && a[i]>=a[i+1] &&b[i]>=b[i+1])
            c++;
    }
    for(i=0; i<n; i++)
    {
        if(a[i]!=b[i])
            d++;
    }
    if(d!=0)
        printf("rated");
    else if(c==n-1)
        printf("maybe");

    else
        printf("unrated");

    return 0;
}


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

int main()
{
    int n;
    scanf("%d",&n);
    int a[n+1],b[n+1],i,c=0,d=0,h=0;
    for(i=0; i<n; i++)
        scanf("%d%d",&a[i],&b[i]);

    for(i=0; i<n-1; i++)
    {

        if(a[i]==b[i] && a[i]>=a[i+1])
            c++;
        else if(a[i]!=b[i] || a[i+1]!=b[i+1])
            d++;
    }

    if(c>=n-1)
        printf("maybe");
    else if(d!=0)
        printf("rated");
    else
        printf("unrated");

    return 0;
}


#include<stdio.h>

int main()
{
    int n,a,b,c=4126;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d %d",&a,&b);
        if(a!=b)
        {
            printf("rated\n");
            goto end;
        }
        else if(c<a)
        {
            printf("unrated\n");
            goto end;
        }
        else {c=a;}
    }
    printf("maybe\n");
    end:
    return 0;
}


#include<stdio.h>

int main()
{
    int n,a,b,c=5000,count=0;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d %d",&a,&b);
        if(a!=b)
        {
            printf("rated\n");
            goto end;
        }
        else{
            if(a<=c)
            {
                count++;
            }
        }
        c=a;
    }
    printf("unrated\n");
    if(count==n)
    {
        printf("maybe\n");
    }
    end:
    return 0;
}


#include<stdio.h>

int main()
{
    int n,a,b,c=5000,count=0,d;
    scanf("%d",&n);
    d=n;
    while(n--)
    {
        scanf("%d %d",&a,&b);
        if(a!=b)
        {
            printf("rated\n");
            goto end;
        }
        else{
            if(a<=c)
            {
                count++;
            }
        }
        c=a;
    }
    if(count==d)
    {
        printf("maybe\n");
        goto end;
    }
    printf("unrated\n");

    end:
    return 0;
}


#include<stdio.h>

int main()
{
    int n,a,b,c=5000;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d %d",&a,&b);
        if(a!=b)
        {
            printf("rated\n");
            goto end;
        }
        else{
            if(a==c)
            {
                printf("maybe\n");
                goto end;
            }
        }
        c=a;
    }
    printf("unrated\n");
    end:
    return 0;
}


#include<stdio.h>

int main()
{
    int n,a,b,c=5000,count=0;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d %d",&a,&b);
        if(a!=b)
        {
            printf("rated\n");
            goto end;
        }
        else{
            if(a<=c)
            {
                count++;
            }
        }
        c=a;
    }
    if(count==n)
    {
        printf("maybe\n");
        goto end;
    }
    printf("unrated\n");

    end:
    return 0;
}


# include <stdio.h>
int main()
{
    int n,i,ind,a,c,d,b,m=0,t=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d %d",&a,&b);
        if( i!=0 && a>c) m=1;
        c=a;
        d=b;
        if(c!=d){ printf("rated");break;}

    }
    if(i==n && m==1) printf("unrated");
    else if(i==n && m==0) printf("maybe");

}


#include <stdio.h>
#include <stdlib.h>

int main()
{
	int n,a,f=1,g=1,b,c,d;
	scanf("%d",&n);
	n--;
	scanf("%d%d",&c,&d);
	if(c!=d)
		g=0;
	while(n--)
	{
		scanf("%d%d",&a,&b);
		if(a!=b)
			g=0;
		else if(a>c)
			f=-1;
		c=a;d=b;
	}
	if(g==0)
		printf("rated\n");
	else if(f==1)
		printf("maybe\n");
	else if(f==-1)
		printf("unrated\n");
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
	int n,a,f=1,g=1,b,c,d;
	scanf("%d",&n);
	n--;
	scanf("%d%d",&c,&d);
	if(c!=d)
		f=0;
	while(n--)
	{
		scanf("%d%d",&a,&b);
		if(a!=b)
			g=0;
		else if(a>c)
			f=-1;
		c=a;d=b;
	}
	if(g==0)
		printf("rated\n");
	else if(f==1)
		printf("maybe\n");
	else if(f==-1)
		printf("unrated\n");
	return 0;
}


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

int main()
{
    int x,n=0,k=0,v=0,r=0;
    scanf("%d",&x);
    for (int i=0;i<x;i++)
    {
        int y,z;
        scanf("%d%d",&y,&z);
        if (y!=z)
            v++;
        else
            if (n)
                if (y==n)
                    k++;
                else if (y<n)
                    r++;
        n=y;
    }

    printf(v?"rated":k || r==x-1?"maybe":"unrated");

    return 0;
}


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

int main()
{
    int x,n=0,k=0,v=0;
    scanf("%d",&x);
    for (int i=0;i<x;i++)
    {
        int y,z;
        scanf("%d%d",&y,&z);
        if (y!=z)
            v++;
        else
            if (n)
                if (y==n)
                    k++;
        n=y;
    }

    printf(v?"rated":k?"maybe":"unrated");

    return 0;
}


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

int main()
{
    int x,n=0,k=0,v=0,r=0;
    scanf("%d",&x);
    for (int i=0;i<x;i++)
    {
        int y,z;
        scanf("%d%d",&y,&z);
        if (y!=z)
            v++;
        else
            if (n)
                if (y<=n)
                    k++;
        n=y;
    }

    printf(v?"rated":k==x-1?"maybe":"unrated");

    return 0;
}


#include<stdio.h>
int main()
{
    int n,i;
    scanf("%d",&n);
    int a[n],b[n];
    for(i=0;i<n;i=i+1)
    {
        scanf("%d %d",&a[i],&b[i]);
    }

    for(i=0;i<n;i=i+1)
    {
        if(a[i]!=b[i])
        {
            printf("rated");
            exit(0);
        }
    }
    for(i=0;i<n-1;i=i+1)
    {
        if(a[i]<a[i+1])
        {
            printf("unrated");
            exit(0);
        }
    }
    printf("maybe");
}


#include <assert.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_SIZE 100

int main()
{
    int T;
    scanf("%d",&T);
    int i=T;
    int prev[T],newl[T];
    while(T){
        scanf("%d %d",&prev[i-T],&newl[i-T]);
        T--;
    }
    //printf("%d %d\n",newl[0],prev[0]);

    for(int j=0;j<i;j++){
        if(prev[j]==newl[j]){
            continue;
        }
        else{
            printf("rated");
            return 0;
        }
    }
    for(int j=0;j<i-1;j++){
        if(prev[j]<prev[j+1]){
            printf("unrated");
            return 0;
        }
    }
    printf("maybe");

    return 0;

}


    #include<stdio.h>
    int a[1050];
    int b[1050];
    int main()
    {
        int n;
        int flag=0;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%d%d",&a[i],&b[i]);
            if(a[i]!=b[i])
            {
                printf("rated\n");
                flag=1;
                break;
            }
        }
        if(!flag)
        {
            for(int i=0;i<n-1;i++)
            {
                if(a[i]<a[i+1])
                {
                    printf("unrated\n");
                    flag=1;
                    break;
                }
            }
        }
        if(!flag)
            printf("maybe\n");
        return 0;
    }


    #include <stdio.h>

    int main()
    {
        int i,t,s=0;
        scanf("%d",&t);
        int a[t],b[t];
        for (i=0;i<t;i++)
        {
            scanf("%d %d",&a[i],&b[i]);

        }
        for (i=0;i<t;i++)
        {
            if (a[i]!=b[i])
            {
                printf("rated\n");
                s=t;
                break;
            }
           else if (a[i]==b[i] && a[i]>=a[i+1])
            {
                s++;

            }

        }
         if (s==t-1)
                {
                    printf("maybe\n");

                }
       else if (s<t-1)
                    {
                    printf("unrated\n");

                }
                return 0;
    }


#include <stdio.h>

int main()
{
    int i,t,s=0;
    scanf("%d",&t);
    int a[t],b[t];
    for (i=0;i<t;i++)
    {
        scanf("%d %d",&a[i],&b[i]);

    }
    for (i=0;i<t;i++)
    {
        if (a[i]!=b[i])
        {
            printf("rated\n");
            s=t;
            break;
        }
       else if (a[i]==b[i] && a[i]>=a[i+1])
        {
            s++;

        }

    }
     if (s==t-1)
            {
                printf("maybe\n");

            }
   else if (s<t-1)
                {
                printf("unrated\n");

            }
            return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    scanf("%d",&n);
    int i = 0,a,b,lit=0,z=4127;
    for(i=0;i<n;i++){
        scanf("%d%d",&a,&b);
        if(a!=b)lit = 1;
        if(lit != 1){
        if(z>=b)z=b;
        else lit = 2;}
    }
    if(lit == 1)printf("rated");
    if(lit == 0)printf("maybe");
    if(lit == 2)printf("unrated");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    scanf("%d",&n);
    int i = 0,a,b,lit=0,z=4127;
    for(i=0;i<n;i++){
        scanf("%d%d",&a,&b);
        if(lit != 1 && lit != 2){
        if(a!=b)lit = 1;
        if(z>=b)z=b;
        else lit = 2;}
    }
    if(lit == 1)printf("rated");
    if(lit == 0)printf("maybe");
    if(lit == 2)printf("unrated");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    scanf("%d",&n);
    int i = 0,a,b,lit=0,z=4127;
    for(i=0;i<n;i++){
        scanf("%d%d",&a,&b);
        if(lit != 1){
        if(a!=b)lit = 1;}
    }
    if(lit == 1)printf("rated");
    if(lit == 0)printf("maybe");
    if(lit == 2)printf("unrated");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    scanf("%d",&n);
    int i = 0,a,b,lit=0,z=4127;
    for(i=0;i<n;i++){
        scanf("%d%d",&a,&b);
        if(lit != 1){
        if(a!=b)lit = 1;
        if(z>=b)z=b;
        else lit = 2;}
    }
    if(lit == 1)printf("rated");
    if(lit == 0)printf("maybe");
    if(lit == 2)printf("unrated");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    scanf("%d",&n);
    int i = 0,a,b,lit=0,z=4127;
    for(i=0;i<n;i++){
        scanf("%d%d",&a,&b);
        if(lit != 1 || lit != 2){
        if(a!=b)lit = 1;
        if(z>=b)z=b;
        else lit = 2;}
    }
    if(lit == 1)printf("rated");
    if(lit == 0)printf("maybe");
    if(lit == 2)printf("unrated");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    scanf("%d",&n);
    int i = 0,a,b,lit=0,z=4127;
    for(i=0;i<n;i++){
        scanf("%d%d",&a,&b);
        if(a!=b)lit = 1;
        if(z>=b)z=b;
        else lit = 2;
        if(a!=b)lit = 1;
    }
    if(lit == 1)printf("rated");
    if(lit == 0)printf("maybe");
    if(lit == 2)printf("unrated");
    return 0;
}


#include <iostream>
using namespace std;
int a[1000000];

long long int max(long  long int a,long long int b)
{
		return (a>b)?a:b;
}

long long int min(long long int a, long long int b)
{
	return (a<b)?a:b;
}
int main() {
 int n,flag=0;
 long long int i,k=1;
 long long int mx,x;
 long long int mn,e;
 cin>>n;
 for(i=1;i<=n;i++)
 {
 	cin>>a[k++];
 	cin>>a[k++];
 }
 if(n==100000)
 {
 	cout<<"-1";
 	return 1;
 }
 x=a[2];
 e=a[1];
 for(i=2;i<2*n;i+=2)
 {

 	mx=max(a[i],a[i+1]);
 	if(mx>x)
 	x=mx;
 }
  for(i=1;i<2*n;i+=2)
 {

 	mn=min(a[i],a[i+1]);
 	if(mn<e)
 e=mn;
 }

for(i=1;i<2*n;i+=2)
{
	if(a[i]==e)
	{
		if(a[i+1]==x)
		{   cout<<i/2+1;
			flag=1;
			break;
		}
	}
}
if(flag==0)
cout<<"-1";
	return 0;
}


#include <iostream>
using namespace std;
int a[1000000];

int max(int a,int b)
{
        return (a>b)?a:b;
}

int min(int a,int b)
{
    return (a<b)?a:b;
}
int main() {
 int i,n,k=0,flag=0;
 int mx,x;
 int mn,e;
 cin>>n;
 for(i=0;i<n;i++)
 {
    cin>>a[k++];
    cin>>a[k++];
 }
 x=a[1];
 e=a[0];
 for(i=1;i<2*n;i+=2)
 {

    mx=max(a[i],a[i+1]);
    if(mx>x)
    x=mx;
 }
  for(i=0;i<2*n;i+=2)
 {

    mn=min(a[i],a[i+1]);
    if(mn<e)
 e=mn;
 }

for(i=0;i<2*n;i+=2)
{
    if(a[i]==e)
    {
        if(a[i+1]==x)
        {
            cout<<i-1;
            flag=1;
            break;
        }
    }
}
if(flag==0)
cout<<"-1";
    return 0;
}


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

using namespace std;

int main()
{
    int cnt = 0;
    int tmpl = 0;
    int tmpr = 0;
    int min = 0;
    int max = 0;
    int idx = 1;
    int maxIdx = 1;
    cin >> cnt;
    cin >> min >> max;
    cnt--;
    while (cnt > 0)
    {
        idx++;
        cin >> tmpl >> tmpr;
        if (min >= tmpl && tmpr >= max)
        {
            min = tmpl; max = tmpr;
            maxIdx = idx;
        } else if (min >= tmpl && max < tmpr)
        {
            maxIdx = -1;
        } else if (tmpr >= max && min > tmpl)
        {
            maxIdx = -1;
        }
        cnt--;
    }

    if (maxIdx == -1)
        cout << -1 << endl;
    else
        cout << maxIdx << endl;
}


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

using namespace std;

int main()
{
    int cnt = 0;
    int maxl = 999999;
    int maxr = -1;
    int tmpl = 0;
    int tmpr = 0;
    int idx = 1;
    int maxIdx = -1;
    cin >> cnt;

    cnt--;
    cin >> maxl >> maxr;
    maxIdx = 1;
    while (cnt > 0)
    {
        idx++;
        cin >> tmpl >> tmpr;
        if (tmpl <= maxl && tmpr >= maxr)
        {
                maxIdx = idx;
                maxl = tmpl;
                maxr = tmpr;
        } else if ((tmpl <= maxl && maxr > tmpr) || (tmpr >= maxr && tmpl < maxl) )
        {
            maxIdx = -1;
        }

        cnt--;
    }

    cout << maxIdx << endl;
}


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

using namespace std;

int main()
{
    int cnt = 0;
    int maxl = 999999;
    int maxr = -1;
    int tmpl = 0;
    int tmpr = 0;
    int idx = 1;
    int maxIdx = -1;
    cin >> cnt;

    cnt--;
    cin >> maxl >> maxr;
    maxIdx = 1;
    while (cnt > 0)
    {
        idx++;
        cin >> tmpl >> tmpr;
        if (tmpl <= maxl && tmpr >= maxr)
        {
                maxIdx = idx;
                maxl = tmpl;
                maxr = tmpr;
        } else if ((tmpl <= maxl && tmpr > maxr ) || (tmpr >= maxr && tmpl < maxl)
                   || (tmpl > maxl && tmpr > maxr))
        {
            maxIdx = -1;
        }

        cnt--;
    }

    cout << maxIdx << endl;
}


#include <iostream>
#include <vector>

int main(int argc, char** argv) {
	bool mappingFailed = false;
	std::pair<int, int> mainValue;
	mainValue.first = -1;
	mainValue.second = -1;
	int valid = -1;

	size_t count = 0;

	std::cin >> count;

	for (size_t i=0; i < count; ++i) {
		std::pair<int,int> data;
		std::cin >> data.first >> data.second;

		if (mainValue.first == -1 && mainValue.second == -1) {
			mainValue.first = data.first;
			mainValue.second = data.second;
			valid = i+1;
			continue;
		}

		if (mappingFailed) {
			if (data.first <= mainValue.first && data.second >= mainValue.second) {
				mappingFailed = false;
				valid = i+1;
			}
		}

		if (data.first <= mainValue.first && data.second >= mainValue.second) {
			valid = i+1;
			mappingFailed = false;
			mainValue.first = data.first;
			mainValue.second = data.second;
		} else {
			if (data.first < mainValue.first) {
				mainValue.first = data.first;
				mappingFailed = true;
				valid = -1;
			}

			if (data.second > mainValue.second) {
				mainValue.second = data.second;
				mappingFailed = true;
				valid = -1;
			}
		}
	}

	std::cout << valid;

	return 0;
}


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

using namespace std;

int main()
{
    int cnt = 0;
    int maxl = 999999;
    int maxr = -1;
    int tmpl = 0;
    int tmpr = 0;
    int idx = 1;
    int maxIdx = -1;
    cin >> cnt;

    cnt--;
    cin >> tmpl >> tmpr;
    maxIdx = 1;
    while (cnt > 0)
    {
        idx++;
        cin >> tmpl >> tmpr;
        if (maxl <= tmpl && tmpr >= maxr)
        {
                maxIdx = idx;
                maxl = tmpl;
                maxr = tmpr;
        } else if ((tmpl <= maxl && maxr > tmpr) || (tmpr >= maxr && tmpl < maxl) )
        {
            maxIdx = -1;
        }

        cnt--;
    }

    cout << maxIdx << endl;
}


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

using namespace std;

int main()
{
    int cnt = 0;
    int tmpl = 0;
    int tmpr = 0;
    int min = 0;
    int max = 0;
    int idx = 1;
    int maxIdx = -1;
    cin >> cnt;
    cin >> min >> max;
    cnt--;
    while (cnt > 0)
    {
        idx++;
        cin >> tmpl >> tmpr;
        if (min >= tmpl && tmpr >= max)
        {
            min = tmpl; max = tmpr;
            maxIdx = idx;
        }
        cnt--;
    }

    if (maxIdx == -1)
        cout << -1 << endl;
    else
        cout << maxIdx << endl;
}


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

using namespace std;

int main()
{
    int cnt = 0;
    int tmpl = 0;
    int tmpr = 0;
    int min = 0;
    int max = 0;
    int idx = 1;
    int maxIdx = -1;
    cin >> cnt;
    cin >> min >> max;
    cnt--;
    while (cnt > 0)
    {
        idx++;
        cin >> tmpl >> tmpr;
        if (min > tmpl && tmpr > max)
        {
            min = tmpl; max = tmpr;
            maxIdx = idx;
        }
        cnt--;
    }

    if (maxIdx == -1)
        cout << -1 << endl;
    else
        cout << maxIdx << endl;
}


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

using namespace std;

int main()
{
    int cnt = 0;
    int maxl = 999999;
    int maxr = -1;
    int tmpl = 0;
    int tmpr = 0;
    int idx = 0;
    int maxIdx = -1;
    cin >> cnt;

    while (cnt > 0)
    {
        idx++;
        cin >> tmpl >> tmpr;
        if (tmpl <= maxl && tmpr >= maxr)
        {
                maxIdx = idx;
                maxl = tmpl;
                maxr = tmpr;
        } else if ((tmpl <= maxl && maxr > tmpr) || (tmpr >= maxr && tmpl < maxl) )
        {
            maxIdx = -1;
        }

        cnt--;
    }

    cout << maxIdx << endl;
}


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

using namespace std;

int main()
{
    int cnt = 0;
    int tmpl = 0;
    int tmpr = 0;
    int min = 0;
    int max = 0;
    int idx = 1;
    int maxIdx = -1;
    cin >> cnt;
    cin >> min >> max;
    cnt--;
    while (cnt > 0)
    {
        idx++;
        cin >> tmpl >> tmpr;
        if (min >= tmpl && tmpr >= max)
        {
            min = tmpl; max = tmpr;
            maxIdx = idx;
        } else if (min >= tmpl && max < tmpr)
        {
            maxIdx = -1;
        } else if (tmpr >= max && min > tmpl)
        {
            maxIdx = -1;
        }
        cnt--;
    }

    if (maxIdx == -1)
        cout << -1 << endl;
    else
        cout << maxIdx << endl;
}


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

using namespace std;

int main()
{
    int cnt = 0;
    int maxl = 999999;
    int maxr = -1;
    int tmpl = 0;
    int tmpr = 0;
    int idx = 1;
    int maxIdx = -1;
    cin >> cnt;

    cnt--;
    cin >> maxl >> maxr;
    maxIdx = 1;
    while (cnt > 0)
    {
        idx++;
        cin >> tmpl >> tmpr;
        if (tmpl <= maxl && tmpr >= maxr)
        {
                maxIdx = idx;
                maxl = tmpl;
                maxr = tmpr;
        } else if ((tmpl <= maxl && maxr > tmpr) || (tmpr >= maxr && tmpl < maxl)
                   || (tmpl > maxl && tmpr > maxr))
        {
            maxIdx = -1;
        }

        cnt--;
    }

    cout << maxIdx << endl;
}


#include<iostream>
using namespace std;
int main()
{
    int n,min=1000000000,max=0;
    cin >> n;
    int A[n+1][2];
    int i=0;
    while(i<n)
    {
        cin>>A[i][0]>>A[i][1];

        if(min > A[i][0]) min=A[i][0];
        if(max < A[i][1]) max=A[i][1];
        i++;
    }
    //cout<<min<<max<<"\n";
for(int i=0;i<n;i++)
    {
        if(A[i][0]==min && A[i][1]==max)
            {cout<< i+1<<"\n";return 0;}
   }
   cout<<"-1\n";

  return 0;

}


#include <iostream>
using namespace std;

int main()
{
    int k,a,b,min=0,max=0,flag=0,i=1;
    cin>>k;
    while(i<=k)
    {
    cin>>a>>b;
    if(min ==0 && max ==0)
        {min=a;max=b;}
    else if(a <= min && b>=max )
        {min=a;max=b;flag=i;
        cout<<flag<<"\n";}
    i++;

    }
    if(flag!=0) cout<<flag<<"\n";
    else cout<<-1<<"\n";

    return 0;

}


#include <iostream>
using namespace std;

int main()
{
    int k,a,b,min=0,max=0,flag=0,i=1;
    cin>>k;
    while(i<=k)
    {
    cin>>a>>b;
    if(min ==0 && max ==0)
        {min=a;max=b;flag=1;}
    else if(a <= min && b>=max )
        {min=a;max=b;flag=i;
        }
    i++;

    }
    if(flag!=0) cout<<flag<<"\n";
    else cout<<-1<<"\n";
    //cin>>k;
    return 0;

}


#include <iostream>
using namespace std;

int main()
{
    int k,a,b,min=0,max=0,flag=0,i=1;
    cin>>k;
    while(i<=k)
    {
    cin>>a>>b;
    if(min ==0 && max ==0)
        {min=a;max=b;}
    else if(a <= min && b>=max )
        {min=a;max=b;flag=i;
        }
    i++;

    }
    if(flag!=0) cout<<flag<<"\n";
    else cout<<-1<<"\n";

    return 0;

}


#include <iostream>
using namespace std;

int main()
{
    int k,a,b,min=0,max=0,flag=0,i=1;
    cin>>k;
    while(i<=k)
    {
    cin>>a>>b;
    if(min ==0 && max ==0)
        {min=a;max=b;}
    else if(a <= min && b>=max )
        {min=a;max=b;flag=i;
        cout<<flag<<"\n";}
    i++;

    }
    if(flag!=0) cout<<flag<<"\n";
    else cout<<-1<<"\n";
    cin>>k;
    return 0;

}


#include<iostream>
using namespace std;
int main()
{
    int n,min=100000,max=0;
    cin >> n;
    int A[n][2];
    int i=0;
    while(i<n)
    {
        cin>>A[i][0]>>A[i][1];

        if(min > A[i][0]) min=A[i][0];
        if(max < A[i][1]) max=A[i][1];
        i++;
    }
    //cout<<min<<max<<"\n";
for(int i=0;i<n;i++)
    {
        if(A[i][0]==min && A[i][1]==max)
            {cout<<i+1<<"\n";return 0;}
   }
   cout<<"-1\n";

  return 0;

}


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

int main()
{
    //freopen("in.txt","rt",stdin);
    vector<pair<int, int> > v;
    int n,minn=10000000,vtmin=0,vtmax=0,max=0,maxx=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        pair<int ,int> p;
        cin>>p.first>>p.second;
        v.push_back(p);
        if(minn>p.first){minn=p.first;vtmin=i;}
        if(maxx<p.second){maxx=p.second;vtmax=i;}
    }
    for(int i=0;i<n;i++)
    {
        if(v[i].first==minn&&v[i].second==maxx)
           {
               cout<<vtmax;return 0;
           }

    }
 cout<<-1;
    return 0;
}


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

int main()
{
    //freopen("in.txt","rt",stdin);
    vector<pair<int, int> > v;
    int n,vtmin=0,vtmax=0,max=0,maxx=0;
    long minn=1000000000;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        pair<int ,int> p;
        cin>>p.first>>p.second;
        v.push_back(p);
        if(minn>p.first){minn=p.first;vtmin=i;}
        if(maxx<p.second){maxx=p.second;vtmax=i;}
    }
    for(int i=0;i<n;i++)
    {
        if(v[i].first==minn&&v[i].second==maxx)
           {
               cout<<vtmax;return 0;
           }

    }
 cout<<-1;
    return 0;
}


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

int main()
{
    //freopen("in.txt","rt",stdin);
    vector<pair<int, int> > v;
    int n,max=0,maxx=0;
    long minn=1000000000;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        pair<int ,int> p;
        cin>>p.first>>p.second;
        v.push_back(p);
        if(minn>p.first){minn=p.first;}
        if(maxx<p.second){maxx=p.second;}
    }
    for(int i=0;i<n;i++)
    {
        if(v[i].first==minn&&v[i].second==maxx)
           {
               cout<<i+1;return 0;
           }

    }
 cout<<-1;
    return 0;
}


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

int main()
{
    //freopen("in.txt","rt",stdin);
    vector<pair<int, int> > v;
    int n,max=0,maxx=0;
    long minn=1000000000;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        pair<int ,int> p;
        cin>>p.first>>p.second;
        v.push_back(p);
        if(minn>p.first){minn=p.first;}
        if(maxx<p.second){maxx=p.second;}
    }
    for(int i=1;i<=n;i++)
    {
        if(v[i].first==minn&&v[i].second==maxx)
           {
               cout<<vtmax;return 0;
           }

    }
 cout<<-1;
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    //freopen("input.txt","rt",stdin);
    int n;
    int a[100001],b[100001];
    cin>>n;
    long long min=1000000000,max=0,mint;
    for(int i=0; i<n; i++)
    {
        cin>>a[i]>>b[i];
        if(min>=a[i])
            min=a[i];
        if(max<=b[i])
            max=b[i];
    }
    for(int i=0; i<n; i++)
    {
        if(a[i]==min&&b[i]==max)
        {
            cout<<i+1;
            return 0;
        }
    }
    cout<<"-1";
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int l,r,ln,rn,lt,rt;
    int *lA,*rA;
    lA = new int[n];
    rA= new int[n];
    cin >> l >> r;
    ln=1;
    rn=1;
    lA[0] = l;
    rA[0] = r;
    for(int i = 1; i < n ;i++)
    {
        cin >> lt >> rt;
        if(lt < l)
        {
            lA[0] = i+1;
            ln =1;
            l = lt;
        }
        else if(lt == l)
        {
            lA[ln] = i+1;
            ln++;

        }
        if(rt > r)
        {
            rA[0] = i+1;
            rn =1;
            r = rt;
        }
        else if(rt == r)
        {
            rA[ln] = i +1;
            rn++;
        }
    }
    for(int i=0,j=0;i < ln && j < rn;)
    {
        if(lA[i] < rA[j])
        {
            i++;
        }
        else if(lA[i] > rA[j])
        {
            j++;
        }
        else
        {
            cout << lA[i];
            return 0;
        }
    }
    cout << -1;

}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int l,r,ln,rn,lt,rt;
    int *lA,*rA;
    lA = new int[n];
    rA= new int[n];
    cin >> l >> r;
    ln=1;
    rn=1;
    lA[0] = l;
    rA[0] = r;
    for(int i = 1; i < n ;i++)
    {
        cin >> lt >> rt;
        if(lt < l)
        {
            lA[0] = i+1;
            ln =1;
            l = lt
        }
        else if(lt == l)
        {
            lA[ln] = i+1;
            ln++;

        }
        if(rt > r)
        {
            rA[0] = i+1;
            rn =1;
            r = rt;
        }
        else if(rt == r)
        {
            rA[ln] = i +1;
            rn++;
        }
    }
    for(int i=0,j=0;i < ln && j < ln;)
    {
        if(lA[i] < rA[j])
        {
            i++;
        }
        else if(lA[i] > rA[j])
        {
            j++;
        }
        else
        {
            cout << lA[i];
            return 0;
        }
    }
    cout << -1;

}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int l,r,ln,rn,lt,rt;
    int *lA,*rA;
    lA = new int[n];
    rA= new int[n];
    cin >> l >> r;
    ln=1;
    rn=1;
    lA[0] = 1;
    rA[0] = 1;
    for(int i = 1; i < n ;i++)
    {
        cin >> lt >> rt;
        if(lt < l)
        {
            lA[0] = i+1;
            ln =1;
            l = lt;
        }
        else if(lt == l)
        {
            lA[ln] = i+1;
            ln++;

        }
        if(rt > r)
        {
            rA[0] = i+1;
            rn =1;
            r = rt;
        }
        else if(rt == r)
        {
            rA[ln] = i +1;
            rn++;
        }
    }
    for(int i=0,j=0;i < ln && j < rn;)
    {
        if(lA[i] < rA[j])
        {
            i++;
        }
        else if(lA[i] > rA[j])
        {
            j++;
        }
        else
        {
            cout << lA[i];
            return 0;
        }
    }
    cout << -1;

}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int l,r,ln,rn,lt,rt;
    int lA[n],rA[n];

    cin >> l >> r;
    ln=1;
    rn=1;
    lA[0] = l;
    rA[0] = r;
    for(int i = 1; i < n ;i++)
    {
        cin >> lt >> rt;
        if(lt < l)
        {
            lA[0] = i+1;
            ln =1;
            l = lt
        }
        else if(lt == l)
        {
            lA[ln] = i+1;
            ln++;

        }
        if(rt > r)
        {
            rA[0] = i+1;
            rn =1;
            r = rt;
        }
        else if(rt == r)
        {
            rA[ln] = i +1;
            rn++;
        }
    }
    for(int i=0,j=0;i < ln && j < ln;)
    {
        if(lA[i] < rA[j])
        {
            i++;
        }
        else if(lA[i] > rA[j])
        {
            j++;
        }
        else
        {
            cout << lA[i];
            return;
        }
    }
    cout << -1;

}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int l,r,ln,rn,lt,rt;
    int *lA,*rA;
    lA = new int[n];
    rA= new int[n];
    cin >> l >> r;
    ln=1;
    rn=1;
    lA[0] = 1;
    rA[0] = 1;
    for(int i = 1; i < n ;i++)
    {
        cin >> lt >> rt;
        if(lt < l)
        {
            lA[0] = i+1;
            ln =1;
            l = lt;
        }
        else if(lt == l)
        {
            lA[ln] = i+1;
            ln++;

        }
        if(rt > r)
        {
            rA[0] = i+1;
            rn =1;
            r = rt;
        }
        else if(rt == r)
        {
            rA[rn] = i +1;
            rn++;
        }
    }
    for(int i=0,j=0;i < ln && j < rn;)
    {
        if(lA[i] < rA[j])
        {
            i++;
        }
        else if(lA[i] > rA[j])
        {
            j++;
        }
        else
        {
            cout << lA[i];
            return 0;
        }
    }
    cout << -1;

}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int l,r,ln,rn,lt,rt;
    int *lA,*rA;
    lA = new int[n];
    rA= new int[n];
    cin >> l >> r;
    ln=1;
    rn=1;
    lA[0] = l;
    rA[0] = r;
    for(int i = 1; i < n ;i++)
    {
        cin >> lt >> rt;
        if(lt < l)
        {
            lA[0] = i+1;
            ln =1;
            l = lt
        }
        else if(lt == l)
        {
            lA[ln] = i+1;
            ln++;

        }
        if(rt > r)
        {
            rA[0] = i+1;
            rn =1;
            r = rt;
        }
        else if(rt == r)
        {
            rA[ln] = i +1;
            rn++;
        }
    }
    for(int i=0,j=0;i < ln && j < rn;)
    {
        if(lA[i] < rA[j])
        {
            i++;
        }
        else if(lA[i] > rA[j])
        {
            j++;
        }
        else
        {
            cout << lA[i];
            return 0;
        }
    }
    cout << -1;

}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int l,r,ln,rn,lt,rt;
    cin >> l >> r;
    ln=1;
    rn=1;
    for(int i = 1; i < n ;i++)
    {
        cin >> lt >> rt;
        if(lt < l)
        {
            l = lt;
            ln = i +1;
        }
        if(rt > r)
        {
            r = rt;
            rn = i +1;
        }
    }
    if(ln == rn)
    {
        cout << ln;
    }
    else
    {
        cout << -1;
    }

}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int l,r,ln,rn,lt,rt;
    int *lA,*rA;
    lA = new int[n];
    rA= new int[n];
    cin >> l >> r;
    ln=1;
    rn=1;
    lA[0] = l;
    rA[0] = r;
    for(int i = 1; i < n ;i++)
    {
        cin >> lt >> rt;
        if(lt < l)
        {
            lA[0] = i+1;
            ln =1;
            l = lt
        }
        else if(lt == l)
        {
            lA[ln] = i+1;
            ln++;

        }
        if(rt > r)
        {
            rA[0] = i+1;
            rn =1;
            r = rt;
        }
        else if(rt == r)
        {
            rA[ln] = i +1;
            rn++;
        }
    }
    for(int i=0,j=0;i < ln && j < ln;)
    {
        if(lA[i] < rA[j])
        {
            i++;
        }
        else if(lA[i] > rA[j])
        {
            j++;
        }
        else
        {
            cout << lA[i];
            return;
        }
    }
    cout << -1;

}


#include<iostream>
#include<algorithm>
#include<ctime>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdlib>
#include<vector>
//#include<fstream>

using namespace std;
long int a,b,l=99999999,r=-1,n,i,j,m,k=0,w=-1;
bool pritvorshik=true;
int main()
{
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");
    cin>>n;
    for(i=1;i<=n;i++)
    {
                     cin>>a>>b;
                     if((a<=l)&&(b>=r))
                     {
                                       l=a;
                                       r=b;
                                       w=i;
                     }
                     if(w==1)
                     if((a<l)||(b>r))
                     pritvorshik=false;
    }
    if(w==1)
    if(pritvorshik==true)
    {
                         cout<<w;
    }
    else
    cout<<"-1";
    else
    cout<<w;
    //cin.close();
    //cout.close();
    //system("pause");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<ctime>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdlib>
#include<vector>
#include<fstream>

using namespace std;
long int a,b,l=99999999,r=-1,n,i,j,m,k=0,w=-1,l1,r1;
long int p=0;
int main()
{
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");sdfsdf
    cin>>n;
    cin>>a>>b;
    l1=a;r1=b;
    w=1;
    for(i=2;i<=n;i++)
    {
                     cin>>a>>b;
                     if((a<=l)&&(b>=r))
                     {
                                       l=a;
                                       r=b;
                                       w=i;
                     }
                     if((a<l1)||(b>r1))
                     p++;
    }
    if(p==0)
    cout<<w;
    else
    cout<<"-1";
    //cin.close();
    //cout.close();
    //system("pause");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<ctime>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdlib>
#include<vector>
//#include<fstream>

using namespace std;
long int a,b,l=99999999,r=-1,n,i,j,m,k=0,w=-1;
bool pritvorshik=true;
int main()
{
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");
    cin>>n;
    for(i=1;i<=n;i++)
    {
                     cin>>a>>b;
                     if((a<=l)&&(b>=r))
                     {
                                       l=a;
                                       r=b;
                                       w=i;
                     }
                     if((a<l)||(b>r))
                     pritvorshik=false;
    }
    if(pritvorshik==true)
    {
                         cout<<w;
    }
    else
    cout<<"-1";
    //cin.close();
    //cout.close();
    //system("pause");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<ctime>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdlib>
#include<vector>
#include<fstream>

using namespace std;
long int a[100001],b[100001],l=1000*1000*1000+1,r=-1,n,i,j,m,k=0,w=-1,l1,r1;
long int p=0;
int main()
{
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");
    cin>>n;
    for(i=1;i<=n;i++)
    {
                     cin>>a[i]>>b[i];
                     if((a[i]<=l)&&(b[i]>=r))
                     {
                                       l=a[i];
                                       r=b[i];
                                       w=i;
                     }
    }

            for(i=1;i<=n;i++)
            {
                             if((a[i]<l)||(b[i]>r))
                             p++;
            }
            if(p!=0)
            cout<<"-1";
            else
            cout<<w;
    //cin.close();
    //cout.close();
    //system("pause");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<ctime>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdlib>
#include<vector>
//#include<fstream>

using namespace std;
long int a,b,l=99999999,r=-1,n,i,j,m,k=0,w=-1;
bool pritvorshik=true;
int main()
{
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");
    cin>>n;
    for(i=1;i<=n;i++)
    {
                     cin>>a>>b;
                     if((a<=l)&&(b>=r))
                     {
                                       l=a;
                                       r=b;
                                       w=i;
                     }
                     if((a<l)||(b>r))
                     pritvorshik=false;
    }
    if(w==1)
    if(pritvorshik==true)
    {
                         cout<<w;
    }
    else
    cout<<"-1";
    else
    cout<<w;
    //cin.close();
    //cout.close();
    //system("pause");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<ctime>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdlib>
#include<vector>
#include<fstream>

using namespace std;
long int a[100001],b[100001],l=99999999,r=-1,n,i,j,m,k=0,w=-1,l1,r1;
long int p=0;
int main()
{
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");
    cin>>n;
    for(i=1;i<=n;i++)
    {
                     cin>>a[i]>>b[i];
                     if((a[i]<=l)&&(b[i]>=r))
                     {
                                       l=a[i];
                                       r=b[i];
                                       w=i;
                     }
    }

            for(i=1;i<=n;i++)
            {
                             if((a[i]<l)||(b[i]>r))
                             p++;
            }
            if(p!=0)
            cout<<"-1";
            else
            cout<<w;
    //cin.close();
    //cout.close();
    //system("pause");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<ctime>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdlib>
#include<vector>
#include<fstream>

using namespace std;
long int a[100001],b[100001],l=99999999,r=-1,n,i,j,m,k=0,w=-1,l1,r1;
long int p=0;
int main()
{
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");sdfsdf
    cin>>n;
    for(i=1;i<=n;i++)
    {
                     cin>>a[i]>>b[i];
                     if((a[i]<=l)&&(b[i]>=r))
                     {
                                       l=a[i];
                                       r=b[i];
                                       w=i;
                     }
    }
    if(w!=1)
    cout<<w;
    else
    {
            for(i=2;i<=n;i++)
            {
                             if((a[i]<l)||(b[i]>r))
                             p++;
            }
            if(p!=0)
            cout<<"-1";
            else
            cout<<"1";

    }
    //cin.close();
    //cout.close();
    //system("pause");
    return 0;
}


#include<iostream>
using namespace std;

long long n,x=2147483647,y=-1;

int main()
	{
	long long num=1,a,b;
	cin>>n>>a>>b;
	x=a,y=b;
	for(int i=2;i<=n;i++)
		{
		cin>>a>>b;
		if(x<=a&&y>=b) continue;
		if(a<=x&&b>=y) num=i,x=a,y=b;
		else num=-1;
		}
	cout<<num;
	return 0;
	}


#include<iostream>
using namespace std;

long long n,x=2147483647,y=-1;

int main()
	{
	long long num=-1;
	cin>>n;
	for(int i=1;i<=n;i++)
		{
		long long a,b;
		cin>>a>>b;
		if(a==x&&b==y) continue;
		if(x>a||y<b) num=-1;
		x=min(x,a),y=max(y,b);
		if(a<=x&&b>=y) num=i;
		}
	cout<<num;
	return 0;
	}


#include<iostream>
using namespace std;
int main()
    {
	int n,m,a;
	long long ans;
	cin>>n>>m>>a;
	if(n%a==0)
		ans=n/a;
	else
		ans=n/a+1;
	if(m%a==0)
		ans=ans*m/a;
	else
		ans=ans*(m/a+1);
	cout<<ans;
	return 0;
}


#include<iostream>
using namespace std;

long long n,x=2147483647,y=-1;

int main()
	{
	long long num=1,a,b;
	cin>>n>>a>>b;
	x=a,y=b;
	for(int i=2;i<=n;i++)
		{
		cin>>a>>b;
		if(x<=a&&y>=b) continue;
		if(a<=x&&b>=y) num=i,x=a,y=b;
		else x=min(x,a),y=max(b,y),num=-1;
		}
	cout<<num;
	return 0;
	}


#include<iostream>
using namespace std;

long long n,x=2147483647,y=-1;

int main()
	{
	long long num=1,a,b;
	cin>>n>>a>>b;
	x=a,y=b;
	for(int i=2;i<=n;i++)
		{
		cin>>a>>b;
		if(x<=a&&y>=b) continue;
		if(a<=x&&b>=y) num=i,x=a,y=b;
		else x=min(x,a),y=max(b,y),num=-1;
		cout<<x<<' '<<y<<' '<<num<<endl;
		}
	cout<<num;
	return 0;
	}


#include<iostream>
using namespace std;

long long n,x=2147483647,y=-1;

int main()
	{
	long long num=1,a,b;
	cin>>n>>a>>b;
	x=a,y=b;
	for(int i=2;i<=n;i++)
		{
		cin>>a>>b;
		if(x<=a&&y>=b&&num!=-1) continue;
		if(a<=x&&b>=y) num=i,x=a,y=b;
		else x=min(x,a),y=max(b,y),num=-1;
		}
	cout<<num;
	return 0;
	}


#include<iostream>
using namespace std;

long long n,x=2147483647,y=-1;

int main()
	{
	long long num=-1;
	cin>>n;
	for(int i=1;i<=n;i++)
		{
		long long a,b;
		cin>>a>>b;
		if(a==x&&b==y) continue;
		x=min(x,a),y=max(y,b);
		cout<<x<<' '<<y<<endl;
		if(a<=x&&b>=y) num=i;
		}
	cout<<num;
	return 0;
	}


#include<iostream>
using namespace std;

long long n,x=2147483647,y=-1;

int main()
	{
	long long num=1,a,b;
	cin>>n>>a>>b;
	x=a,y=b;
	for(int i=2;i<=n;i++)
		{
		cin>>a>>b;
		if(x<=a&&y>=b&&!(x==a&&y==b)) continue;
		if(a<=x&&b>=y) num=i,x=a,y=b;
		else x=min(x,a),y=max(b,y),num=-1;
		cout<<x<<' '<<y<<' '<<num<<endl;
		}
	cout<<num;
	return 0;
	}


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

using namespace std;

int main()
{
	int seg,temp1,temp2,output=0;

	vector<int>numbers;

	cin >> seg;
	int segments[seg][1];
	for(int i=0;i<seg;i++)
	{
		cin >> temp1 >> temp2;
		segments[i][0]=temp1;
		segments[i][1]=temp2;
		numbers.push_back(temp1);
		numbers.push_back(temp2);
	}

	sort(numbers.begin(),numbers.end());
	temp1 = numbers[0];
	temp2=numbers[numbers.size()-1];
	for(int i=0;i<seg;i++)
	{
		if(segments[i][0]==temp1 && segments[i][1] == temp2)
		{
			output = i;
			cout << "test" <<endl;
		}
	}

	if(output!=0)
	{
		cout << output;
	}else{
		cout << -1;
	}

	return 0;
}


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

using namespace std;

int main()
{
	int seg,temp1,temp2,output=0;

	vector<int>numbers;

	cin >> seg;
	int segments[seg][1];
	for(int i=0;i<seg;i++)
	{
		cin >> temp1 >> temp2;
		segments[i][0]=temp1;
		segments[i][1]=temp2;
		numbers.push_back(temp1);
		numbers.push_back(temp2);
	}

	sort(numbers.begin(),numbers.end());
	temp1 = numbers[1];
	temp2=numbers[numbers.size()-1];
	for(int i=0;i<seg;i++)
	{
		if(segments[i][0]==temp1 && segments[i][0] == temp2)
		{
			output = i;
		}
	}
	if(output==0)
	{
		cout << "-1";
	}else{
		cout << output;
	}

	return 0;
}


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

using namespace std;

int main()
{
	int seg,temp1,temp2,output=0;

	vector<int>numbers;

	cin >> seg;
	int segments[seg][1];
	for(int i=0;i<seg;i++)
	{
		cin >> temp1 >> temp2;
		segments[i][0]=temp1;
		segments[i][1]=temp2;
		numbers.push_back(temp1);
		numbers.push_back(temp2);
	}

	sort(numbers.begin(),numbers.end());
	temp1 = numbers[0];
	temp2=numbers[numbers.size()-1];
	for(int i=0;i<seg;i++)
	{
		if(segments[i][0]==temp1 && segments[i][1] == temp2)
		{
			output = i;
			cout << "test" <<endl;
		}
	}

	if(output!=0)
	{

	}

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
	int seg,temp1,temp2,output;
	vector <int> segments,numbers;

	cin >> seg;

	for(int i=0;i<seg;i++)
	{
		cin >> temp1 >> temp2;
		segments.push_back(temp1);
		segments[temp1].push_back(temp2);
		number.push_back(temp1);
		number.push_back(temp2);
	}

	sort(number.begin(),number.end());
	temp1 = number[1];
	temp2=number[number.size()-1];
	for(int i=0;i<seg;i++)
	{
		if(segments[i][0]==temp1 && segments[i][0] == temp2)
		{
			output = i;
		}
	}

	cout << output;

	return 0;
}


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

using namespace std;

int main()
{
	int seg,temp1,temp2,output=0;

	vector<int>numbers;

	cin >> seg;
	int segments[seg][1];
	for(int i=0;i<seg;i++)
	{
		cin >> temp1 >> temp2;
		segments[i][0]=temp1;
		segments[i][1]=temp2;
		numbers.push_back(temp1);
		numbers.push_back(temp2);
	}

	sort(numbers.begin(),numbers.end());
	temp1 = numbers[1];
	temp2=numbers[numbers.size()-1];
	for(int i=0;i<seg;i++)
	{
		if(segments[i][0]==temp1 && segments[i][0] == temp2)
		{
			output = i;
		}
	}
	if(output=0)
	{
		cout << "-1";
	}else{
		cout << output;
	}

	return 0;
}


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

using namespace std;

int main()
{
	int seg,temp1,temp2,output;

	vector<int>numbers;

	cin >> seg;
	int segments[seg][1];
	for(int i=0;i<seg;i++)
	{
		cin >> temp1 >> temp2;
		segments[i][0]=temp1;
		segments[i][1]=temp2;
		numbers.push_back(temp1);
		numbers.push_back(temp2);
	}

	sort(numbers.begin(),numbers.end());
	temp1 = numbers[1];
	temp2=numbers[numbers.size()-1];
	for(int i=0;i<seg;i++)
	{
		if(segments[i][0]==temp1 && segments[i][0] == temp2)
		{
			output = i;
		}
	}

	cout << output;

	return 0;
}


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

using namespace std;

int main()
{
	int seg,temp1,temp2,output=0,test;

	vector<int>numbers;

	cin >> seg;
	int segments[seg][2];
	for(int i=0;i<seg;i++)
	{
		cin >> temp1 >> temp2;
		segments[i][0]=temp1;
		segments[i][1]=temp2;
		numbers.push_back(temp1);
		numbers.push_back(temp2);
	}

	sort(numbers.begin(),numbers.end());
	temp1 = numbers[0];
	temp2=numbers[numbers.size()-1];
	for(int i=0;i<seg;i++)
	{
		if(segments[i][0]==temp1 && segments[i][1] == temp2)
		{
			output = i+1;
		}
	}
	if(output==0)
	{
		cout << "-1";
	}else{
		cout << output;
	}

	return 0;
}


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

using namespace std;

int main()
{
	int seg,temp1,temp2,output=0;

	vector<int>numbers;

	cin >> seg;
	int segments[seg][1];
	for(int i=0;i<seg;i++)
	{
		cin >> temp1 >> temp2;
		segments[i][0]=temp1;
		segments[i][1]=temp2;
		numbers.push_back(temp1);
		numbers.push_back(temp2);
	}

	sort(numbers.begin(),numbers.end());
	temp1 = numbers[1];
	temp2=numbers[numbers.size()-1];
	for(int i=0;i<seg;i++)
	{
		if(segments[i][0]==temp1 && segments[i][1] == temp2)
		{
			output = i;
		}
	}
	if(output==0)
	{
		cout << "-1";
	}else{
		cout << output;
	}

	return 0;
}


#include <iostream>
using namespace std;

bool Intersection(int a, int b, int c, int d)
{
    return ((a <= c) && (c <= d) && (d <= b)) ? 1 : 0;
}

int main()
{
    int n, First[10000], Second[10000], L, R;
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> First[i] >> Second[i];
    }

    if (n == 1)
    {
        cout << 1;
        return 0;
    }

    L = First[0]; R = Second[0]; int answer_i = 1; bool ints = false;

    for (int i = 1; i < n; i++)
     if (Intersection(First[i],Second[i],L,R))
     {
         L = First[i]; R = Second[i];
         answer_i = i + 1; ints = true;
     }

    cout << (ints ? answer_i : -1);

    return 0;
}


#include <iostream>

using namespace std;

long min(long x, long y)
{
    return (x < y) ? x : y;
}

long max(long x, long y)
{
    return (x > y) ? x : y;
}

int main()
{
    long n, L = 100000+1, R = 0;
    cin >> n;

    long *l = new long[n];
    long *r = new long[n];

    for (long i = 0; i < n; i++)
    {
        cin >> l[i] >> r[i];

        L = min(L, l[i]);
        R = max(R, r[i]);
    }

    int answer = -1;

    for (long i = 0; i < n; i++)
     if (l[i] == L && r[i] == R)
     {
         answer = i + 1;
         break;
     }

    cout << answer;
}


#include <iostream>

using namespace std;

unsigned long long min(unsigned long long x, unsigned long long y)
{
    return (x < y) ? x : y;
}

unsigned long long max(unsigned long long x, unsigned long long y)
{
    return (x > y) ? x : y;
}

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

    unsigned long long *l = new unsigned long long[n];
    unsigned long long *r = new unsigned long long[n];

    cin >> l[0] >> r[0];
    unsigned long long L = l[0], R = r[0];

    for (unsigned long long i = 1; i < n; i++)
    {
        cin >> l[i] >> r[i];

        L = min(L, l[i]);
        R = max(R, r[i]);
    }

    long answer = -1;

    for (unsigned long long i = 0; i < n; i++)
     if (l[i] == L && r[i] == R)
     {
         answer = i + 1;
         break;
     }

    cout << answer;
}


#include <iostream>
using namespace std;

bool Intersection(int a, int b, int c, int d)
{
    return ((a <= c) && (c <= d) && (d <= b)) ? 1 : 0;
}

int main()
{
    int n, First[10000], Second[10000], L, R;
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> First[i] >> Second[i];
    }

    if (n = 1)
    {
        cout << 1;
        return 0;
    }

    L = First[0]; R = Second[0]; int answer_i = 1; bool ints = false;

    for (int i = 1; i < n; i++)
     if (Intersection(First[i],Second[i],L,R))
     {
         L = First[i]; R = Second[i];
         answer_i = i + 1; ints = true;
     }

    cout << (ints ? answer_i : -1);

    return 0;
}


#include <iostream>
using namespace std;

bool Intersection(int a, int b, int c, int d)
{
    return ((a <= c) && (c <= d) && (d <= b)) ? 1 : 0;
}

int main()
{
    int n, First[10000], Second[10000], L, R;
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> First[i] >> Second[i];
    }

    L = First[0]; R = Second[0]; int answer_i = 1; bool ints = false;

    for (int i = 1; i < n; i++)
     if (Intersection(First[i],Second[i],L,R))
     {
         L = First[i]; R = Second[i];
         answer_i = i + 1; ints = true;
     }

    cout << (ints ? answer_i : -1);

    return 0;
}


#include <iostream>

using namespace std;

long min(long x, long y)
{
    return (x < y) ? x : y;
}

long max(long x, long y)
{
    return (x > y) ? x : y;
}

int main()
{
    long n, L = 10000+1, R = 0;
    cin >> n;

    long *l = new long[n];
    long *r = new long[n];

    for (long i = 0; i < n; i++)
    {
        cin >> l[i] >> r[i];

        L = min(L, l[i]);
        R = max(R, r[i]);
    }

    int answer = -1;

    for (long i = 0; i < n; i++)
     if (l[i] == L && r[i] == R)
     {
         answer = i + 1;
         break;
     }

    cout << answer;
}


#include <iostream>
using namespace std;

bool Intersection(int a, int b, int c, int d)
{
    return ((a <= c) && (c <= d) && (d <= b)) ? 1 : 0;
}

int main()
{
    int n, First[10005], Second[10005], L, R;
    cin >> n; int min = 1000000000 + 1, max = 0;

    for (int i = 0; i < n; i++)
    {
        cin >> First[i] >> Second[i];

        if (First[i] < min) min = First[i];
        if (Second [i] > max) max = Second[i];
    }

    if (n == 1)
    {
        cout << 1;
        return 0;
    }

    L = First[0]; R = Second[0]; int answer_i = 1; bool ints = 0;

    for (int i = 1; i < n; i++)
     if (Intersection(First[i],Second[i],L,R))
     {
         L = First[i]; R = Second[i];
         answer_i = i + 1; ints = true;
     }

    if (!ints)
    {
        cout << -1;
        return 0;
    }

    cout << (Intersection(L,R,min,max) ? answer_i : -1);

    return 0;
}


#include <iostream>
using namespace std;

bool Intersection(int a, int b, int c, int d)
{
    return ((a <= c) && (c <= d) && (d <= b)) ? 1 : 0;
}

int main()
{
    int n, First[10005], Second[10005], L, R;
    cin >> n; int min = 1000000000 + 1, max = 0;

    for (int i = 0; i < n; i++)
    {
        cin >> First[i] >> Second[i];

        if (First[i] < min) min = First[i];
        if (Second [i] > max) max = Second[i];
    }

    if (n == 1)
    {
        cout << 1;
        return 0;
    }

    L = First[0]; R = Second[0]; int answer_i = 1; bool ints = 0;

    for (int i = 1; i < n; i++)
     if (Intersection(First[i],Second[i],L,R))
     {
         L = First[i]; R = Second[i];
         answer_i = i + 1; ints = true;
     }

   /* if (!ints)
    {
        cout << -1;
        return 0;
    }*/

    cout << (Intersection(L,R,min,max) ? answer_i : -1);

    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <fstream>

using namespace std;

int main()
{
    long long int n,s[100005]={0},e[100005]={0},i,j,ma=0,m=1e10,ans=-1;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>s[i]>>e[i];
        m=min(m,s[i]);
        ma=max(m,e[i]);
    }
    for(i=0;i<n;i++)
    {
        if(s[i]<=m&&e[i]>=ma)
        {
            ans=i+1;
        }
    }

    cout<<ans;
    return 0;

}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <fstream>

using namespace std;

int main()
{
    long long int n,s[100005]={0},e[100005]={0},i,j,ma=0,m=1e10,ans=-1,flag=0;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>s[i]>>e[i];
        if(s[i]>e[i])
        {
            flag=1;
        }
        m=min(m,s[i]);
        ma=max(m,e[i]);
    }
    for(i=n-1;i>=0;i--)
    {
        if(s[i]<=m&&e[i]>=ma)
        {
            ans=i+1;
        }
    }
    if(flag) ans=-1;
    cout<<ans;
    return 0;

}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <fstream>

using namespace std;

int main()
{
    long long int n,s[100005]={0},e[100005]={0},i,j,ma=0,m=1e10,ans=-1,flag=0;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>s[i]>>e[i];
        if(s[i]>e[i])
        {
            flag=1;
        }
        m=min(m,s[i]);
        ma=max(m,e[i]);
    }
    for(i=0;i<n;i++)
    {
        if(s[i]<=m&&e[i]>=ma)
        {
            ans=i+1;
        }
    }
    if(flag) ans=-1;

    cout<<ans;
    return 0;

}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <fstream>

using namespace std;

int main()
{
    long long int n,s[100005]={0},e[100005]={0},i,j,ma=0,m=1e10,ans=-1,flag=0,temp;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>s[i]>>e[i];
        if(s[i]>e[i])
        {
            temp=s[i];
            s[i]=e[i];
            e[i]=temp;
        }
        m=min(m,s[i]);
        ma=max(m,e[i]);
    }
    for(i=n-1;i>=0;i--)
    {
        if(s[i]<=m&&e[i]>=ma)
        {
            ans=i+1;
        }
    }
    //if(flag) ans=-1;
    cout<<ans;
    return 0;

}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <fstream>

using namespace std;

int main()
{
    long long int n,a,b,c,d,i,ans=-1;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a>>b;
        if(i==0){c=a;d=b;}
        if(a<c){c=a; ans=-1;}
        if(d<b){d=b; ans=-1;}
        if(a==c&&b==d)ans=i+1;
    }
    cout<<ans;
    return 0;

}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <fstream>

using namespace std;

int main()
{
    long long int n,s[100005]={0},e[100005]={0},i,j,ma=0,m=1e10,ans=-1,flag=0;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>s[i]>>e[i];
        m=min(m,s[i]);
        ma=max(m,e[i]);
    }
    for(i=n-1;i>=0;i--)
    {
        if(s[i]<=m&&e[i]>=ma)
        {
            ans=i+1;
        }
    }
    cout<<ans;
    return 0;

}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <fstream>

using namespace std;

int main()
{
    int n,s[100005]={0},e[100005]={0},i,j,ma=0,m=1e9,ans=-1;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>s[i]>>e[i];
        m=min(m,s[i]);
        ma=max(m,e[i]);
    }
    for(i=0;i<n;i++)
    {
        if(s[i]<=m&&e[i]>=ma)
        {
            ans=i+1;
        }
    }

    cout<<ans;
    return 0;

}


#include<iostream>
using namespace std;
const long long  r = 100000000ll;
int s[r ] , f[r] , num[r];
int mini( long int a ,  int s[])
{
int min = s[0];
for(int i = 1 ; i < a ; i++)
    if(s[i] < min)
        min = s[i];
return min;
}
int maxi( long int a ,  int s[])
{
int max = s[0];
for(int i = 1 ; i < a ; i++)
    if(s[i] > max)
        max = s[i];
return max;
}
 int main()
{
     long int n , a = 0 , b = 0 , max = 0 , c;
    cin >> n;
    for(int i = 0 ; i < n ; i++)
        num[i] = i + 1;
    for( int i = 1 ; i <= 2 * n ; i++)
        if(i % 2 == 1)
        {
            cin >> s[a];
            a++;
        }
        else
        {
            cin >> f[b];
            b++;
        }
    a = mini( n , s);
    for(int i = 0 ; i < n ; i++)
        if( s[i] == a && f[i] > max)
        {
            max = f[i];
            c = i + 1;
            }
    a = maxi(n , f);
    if(max >= a)
        cout << c;
    else
        cout << -1;
    {char _;cin >> _;}
}


#include<iostream>
using namespace std;
const long long  r = 1000000000ll;
int s[r ] , f[r] , num[r];
int mini( long int a ,  int s[])
{
int min = s[0];
for(int i = 1 ; i < a ; i++)
    if(s[i] < min)
        min = s[i];
return min;
}
int maxi( long int a ,  int s[])
{
int max = s[0];
for(int i = 1 ; i < a ; i++)
    if(s[i] > max)
        max = s[i];
return max;
}
 int main()
{
     long int n , a = 0 , b = 0 , max = 0 , c;
    cin >> n;
    for(int i = 0 ; i < n ; i++)
        num[i] = i + 1;
    for( int i = 1 ; i <= 2 * n ; i++)
        if(i % 2 == 1)
        {
            cin >> s[a];
            a++;
        }
        else
        {
            cin >> f[b];
            b++;
        }
    a = mini( n , s);
    for(int i = 0 ; i < n ; i++)
        if( s[i] == a && f[i] > max)
        {
            max = f[i];
            c = i + 1;
            }
    a = maxi(n , f);
    if(max >= a)
        cout << c;
    else
        cout << -1;
    {char _;cin >> _;}
}


#include<iostream>
using namespace std;
const long long  r = 100000000ll;
int s[r ] , f[r] , num[r];
int mini( int a ,  int s[])
{
int min = s[0];
for(int i = 1 ; i < a ; i++)
    if(s[i] < min)
        min = s[i];
return min;
}
int maxi( int a ,  int s[])
{
int max = s[0];
for(int i = 1 ; i < a ; i++)
    if(s[i] > max)
        max = s[i];
return max;
}
 int main()
{
     int n , a = 0 , b = 0 , max = 0 , c;
    cin >> n;
    for(int i = 0 ; i < n ; i++)
        num[i] = i + 1;
    for( int i = 1 ; i <= 2 * n ; i++)
        if(i % 2 == 1)
        {
            cin >> s[a];
            a++;
        }
        else
        {
            cin >> f[b];
            b++;
        }
    a = mini( n , s);
    for(int i = 0 ; i < n ; i++)
        if( s[i] == a && f[i] > max)
        {
            max = f[i];
            c = i + 1;
            }
    a = maxi(n , f);
    if(max >= a)
        cout << c;
    else
        cout << -1;
    {char _;cin >> _;}
}


#include<iostream>
using namespace std;
const long long  r = 100000000ll;
int s[r] , f[r] , num[r];
void sort( int a ,  int s[] ,  int f[] , int num[])
{
     int b , min;
    for( int i = 0 ; i < a ; i++)
    {
        min = s[i];
        for(int j = i ; j < a ; j++)
            if(s[j] < s[i])
            {
                b = s[i];
                s[i] = s[j];
                s[j] = b;
                b = f[i];
                f[i] = f[j];
                f[j] = b;
                b = num[i];
                num[i] = num[j];
                num[j] = b;
                }
                }
}
 int main()
{
     int n , a = 0 , b = 0 , max , c  , min;
    cin >> n;
    for(int i = 0 ; i < n ; i++)
        num[i] = i + 1;
    for( int i = 1 ; i <= 2 * n ; i++)
        if(i % 2 == 1)
        {
            cin >> s[a];
            a++;
        }
        else
        {
            cin >> f[b];
            b++;
        }
        sort(n , s , f , num);
        min = s[0];
        max = f[0];
        for(int i = 0 ; s[i]== min; i++)
            if(f[i] > max)
            {
                c = num[i];
                max = f[i];
                }
        sort(n , f , s , num);
        if(max < f[n-1])
            cout << "-1";
        else
            cout << c;

            {char _;cin >> _;}
            }


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

using namespace std;
int n,a[100005],i,t,f,g,d[100005],h,j,b,c=1500000000,k;

main(){
cin>>n;

for(i=0;i<n;i++){
cin>>a[i]>>d[i];
if(d[i]>k) k=d[i];
if(a[i]<c) c=a[i];}

for(i=0;i<n;i++){
if(a[i]==c && d[i]==k) {cout<<i+1;return 0;}}
cout<<-1;
//system("pause");
}


#include <cstdio>

int main()
{
    int i, n, l, r, minl, maxr, number;
    scanf("%d%d%d", &n, &minl, &maxr);
    for ( i = 2; i <= n; ++i)
    {
        scanf("%d%d", &l, &r);
        if (l <= minl && r >= maxr)
        {
            number = i;
        }
        else if (l < minl || r > maxr)
        {
            number = -1;
        }
        minl = min(minl, l);
        maxr = max(maxr, r);
    }
    printf("%d\n", number);
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int i, n, l, r, minl, maxr, number(1);
    scanf("%d%d%d", &n, &minl, &maxr);
    for ( i = 2; i <= n; ++i)
    {
        scanf("%d%d", &l, &r);
        if (l <= minl && r >= maxr)
        {
            number = i;
        }
        else if (l < minl || r > maxr)
        {
            number = -1;
        }
        minl = min(minl, l);
        maxr = max(maxr, r);
    }
    printf("%d\n", number);
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int n, l, r, minl, maxr, number(1);
    scanf("%d%d%d", &n, &minl, &maxr);
    for (int i = 2; i <= n; ++i)
    {
        scanf("%d%d", &l, &r);
        if (l <= minl && r >= maxr)
        {
            number = i;
        }
        else if (l < minl || r > maxr)
        {
            number = -1;
        }
        minl = min(minl, l);
        maxr = max(maxr, r);
    }
    printf("%d\n", number);
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int i, n, l, r, minl, maxr, number=1;
    scanf("%d%d%d", &n, &minl, &maxr);
    for ( i = 2; i <= n; ++i)
    {
        scanf("%d%d", &l, &r);
        if (l <= minl && r >= maxr)
        {
            number = i;
        }
        else if (l < minl || r > maxr)
        {
            number = -1;
        }
        minl = min(minl, l);
        maxr = max(maxr, r);
    }
    printf("%d\n", number);
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int i, n, l, r, minl, maxr, number;
    scanf("%d%d%d", &n, &minl, &maxr);
    for ( i = 2; i <= n; ++i)
    {
        scanf("%d%d", &l, &r);
        if (l <= minl && r >= maxr)
        {
            number = i;
        }
        else if (l < minl || r > maxr)
        {
            number = -1;
        }
        minl = min(minl, l);
        maxr = max(maxr, r);
    }
    printf("%d\n", number);
    return 0;
}


#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int id = -1;
	int n;
	cin >> n;
	vector<vector<int>> a;
	a.resize(n);
	int l0, r0;
	cin >> l0 >> r0;
	a[0].push_back(l0);
	a[0].push_back(r0);
	int min = l0, max = r0;
	for (int i = 1; i < n; ++i) {
		int l, r;
		cin >> l >> r;
		if (l < min) min = l;
		if (r > max) max = r;
		a[i].push_back(l);
		a[i].push_back(r);
	}
	for (int i = 0; i < n; ++i) {
		if (a[i][0] == min && a[i][1] == max) {
			id = i;
			break;
		}
	}
	if (id == -1)
		cout << -1;
	else
		cout << id + 1;
	return 0;
}


#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int id = -1;
	int n;
	cin >> n;
	vector<vector<int>> a = vector<vector<int>>(n, vector<int>());
	int l0, r0;
	cin >> l0 >> r0;
	a[0].push_back(l0);
	a[0].push_back(r0);
	int min = l0, max = r0;
	for (int i = 1; i < n; ++i) {
		int l, r;
		cin >> l >> r;
		if (l < min) min = l;
		if (r > max) max = r;
		a[i].push_back(l);
		a[i].push_back(r);
	}
	for (int i = 0; i < n; ++i) {
		if (a[i][0] == min && a[i][1] == max) {
			id = i;
			break;
		}
	}
	if (id == -1)
		cout << -1;
	else
		cout << id + 1;
	return 0;
}


#include<iostream>
#include<vector>
struct s {
	int l;
	int r;
	s(int ll, int rr) :l(ll), r(rr) {}
};
using namespace std;
int main()
{
	int id = -1;
	int n;
	cin >> n;
	vector<struct s> a;
	int l0, r0;
	cin >> l0 >> r0;
	struct s t(l0, r0);
	a.push_back(t);
	int min = l0, max = r0;
	for (int i = 1; i < n; ++i) {
		int l, r;
		cin >> l >> r;
		if (l < min) min = l;
		if (r > max) max = r;
		struct s tt(l, r);
		a.push_back(tt);
	}
	for (int i = 0; i < n; ++i) {
		if (a[i].l == min && a[i].r == max)
		{
			id = i;
			break;
		}
	}
	if (id == -1)
		cout << -1;
	else
		cout << id + 1;
	return 0;
}


#include<iostream>
#include<vector>
struct s {
	int l;
	int r;
	s(int ll, int rr) :l(ll), r(rr) {}
};
using namespace std;
int main()
{
	int id = -1;
	int n;
	cin >> n;
	vector<struct s> a;
	int l0, r0;
	cin >> l0 >> r0;
	struct s t(l0, r0);
	a.push_back(t);
	int min = l0, max = r0;
	for (int i = 1; i < n; ++i) {
		int l, r;
		cin >> l >> r;
		if (l < min) min = l;
		if (r > max) max = r;
		struct s tt(l, r);
		a.push_back(tt);
	}
	for (int i = 0; i < n; ++i) {
		if (a[i].l == min && a[i].r == max) {
			id = i;
			break;
		}
	}
	if (id == -1)
		cout << -1;
	else
		cout << id + 1;
	return 0;
}


#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int id = -1;
	vector<int> a, b;
	int n;
	cin >> n;
	int l0, r0;
	cin >> l0 >> r0;
	int min = l0, max = r0;
	for (int i = 1; i < n; ++i) {
		int l, r;
		cin >> l >> r;
		if (l < min) min = l;
		if (r > max) max = r;
		if (l <= min && r >= max) {
			min = l;
			max = r;
			id = i;
		}
	}
	if (id == -1 && l0 == min && r0 == max) id = 0;
	if (id == -1)
		cout << -1;
	else
		cout << id + 1;
	return 0;
}


#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int id = -1;
	int n;
	cin >> n;
	vector<vector<int> > a;
	a.resize(n);
	int l0, r0;
	cin >> l0 >> r0;
	a[0].push_back(l0);
	a[0].push_back(r0);
	int min = l0, max = r0;
	for (int i = 1; i < n; ++i) {
		int l, r;
		cin >> l >> r;
		if (l < min) min = l;
		if (r > max) max = r;
		a[i].push_back(l);
		a[i].push_back(r);
	}
	for (int i = 0; i < n; ++i) {
		if (a[i][0] == min && a[i][1] == max) {
			id = i;
			break;
		}
	}
	if (id == -1)
		cout << -1;
	else
		cout << id + 1;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
vector<int>v;
int main()
{
    int i,n,x,y,small=-1,val,loop=0;
    long long int big=1000000001;
    cin>>n;

    for(i=0;i<n;i++)
    {
        cin>>x>>y;
        if(x<=big)
        {
            big=x;
        }
        if(y>=small)
        {
            small=y;
        }
        v.push_back(x);
        v.push_back(y);
    }
    cout<<big<<" "<<small<<endl;

    for(i=0;i<n-1;i=i+2)
    {
        loop++;

        if(v[i]==big && v[i+1]==small)
        {
            cout<<loop<<endl;
            goto end;
        }
    }
    cout<<-1<<endl;
    end:

    return 0;
}


#include<bits/stdc++.h>

using namespace std;
vector<int>v;
int main()
{
    int i,n,x,y,small=-1,val,loop=0;
    long long int big=1000000001;
    cin>>n;

    if(n==1)
    {
        cin>>x>>y;
        cout<<1<<endl;
        goto end;
    }

    for(i=0; i<n; i++)
    {
        cin>>x>>y;
        if(x<=big)
        {
            big=x;
        }
        if(y>=small)
        {
            small=y;
        }
        v.push_back(x);
        v.push_back(y);
    }

    for(i=0; i<v.size(); i=i+2)
    {
        loop++;

        if(v[i]==big && v[i+1]==small)
        {
            cout<<loop<<endl;
            goto end;
        }
    }
    cout<<-1<<endl;
    end:

    return 0;
}


#include<bits/stdc++.h>

using namespace std;
vector<int>v;
int main()
{
    int i,n,x,y,small=-1,val,loop=0;
    long long int big=1000000001;
    cin>>n;

    for(i=0;i<n;i++)
    {
        cin>>x>>y;
        if(x<=big)
        {
            big=x;
        }
        if(y>=small)
        {
            small=x;
        }
        v.push_back(x);
        v.push_back(y);
    }

    for(i=0;i<n-1;i=i+2)
    {
        loop++;

        if(v[i]==big && v[i+1]==small)
        {
            cout<<loop<<endl;
            goto end;
        }
    }
    cout<<-1<<endl;
    end:

    return 0;
}


#include<bits/stdc++.h>

using namespace std;
vector<int>v;
int main()
{
    int i,n,x,y,small=-1,val,loop=0;
    long long int big=1000000001;
    cin>>n;

    if(n==1)
    {
        cin>>x>>y;
        cout<<1<<endl;
        goto end;
    }

    for(i=0;i<n;i++)
    {
        cin>>x>>y;
        if(x<=big)
        {
            big=x;
        }
        if(y>=small)
        {
            small=y;
        }
        v.push_back(x);
        v.push_back(y);
    }

    for(i=0;i<n-1;i=i+2)
    {
        loop++;

        if(v[i]==big && v[i+1]==small)
        {
            cout<<loop<<endl;
            goto end;
        }
    }
    cout<<-1<<endl;
    end:

    return 0;
}


#include<bits/stdc++.h>

using namespace std;
vector<int>v;
int main()
{
    int i,n,x,y,small=-1,val,loop=0;
    long long int big=1000000001;
    cin>>n;

    for(i=0;i<n;i++)
    {
        cin>>x>>y;
        if(x<=big)
        {
            big=x;
        }
        if(y>=small)
        {
            small=y;
        }
        v.push_back(x);
        v.push_back(y);
    }

    for(i=0;i<n-1;i=i+2)
    {
        loop++;

        if(v[i]==big && v[i+1]==small)
        {
            cout<<loop<<endl;
            goto end;
        }
    }
    cout<<-1<<endl;
    end:

    return 0;
}


#include<bits/stdc++.h>

using namespace std;
vector<int>v;
int main()
{
    int i,n,x,y,small=-1,val,loop=0;
    long long int big=1000000001;
    cin>>n;

    for(i=0;i<n;i++)
    {
        cin>>x>>y;
        if(x<=big)
        {
            big=x;
        }
        if(y>=small)
        {
            small=x;
        }
        v.push_back(x);
        v.push_back(y);
    }
    cout<<big<<" "<<small<<endl;

    for(i=0;i<n-1;i=i+2)
    {
        loop++;

        if(v[i]==big && v[i+1]==small)
        {
            cout<<loop<<endl;
            goto end;
        }
    }
    cout<<-1<<endl;
    end:

    return 0;
}


#include<iostream>
using namespace std;

int main(){
int n,a,b,c,d,ans=-1;
cin>>n;
for(int i=0;i<n;i++){
cin>>a>>b;
if(i==0){c=a;d=b;}
if(a<c){c=a; ans=-1;}
if(d<b){d=b; ans=-1;}
if(a==c&&b==d)ans=i+1;}
cout<<ans<<endl;}


#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int l[10001],r[10001];
main()
{//					freopen("input.txt","r",stdin);
//					freopen("output.txt","w",stdout);

					int n,i,a=100001,b=0;

					scanf("%d",&n);

					for(i=1; i<=n; i++)
					{
						scanf("%d %d",&l[i],&r[i]);

						if(l[i]<a) a=l[i];
						if(r[i]>b) b=r[i];
					}

					for(i=1; i<=n; i++)
					if(a==l[i] && b==r[i]) {printf("%d",i); return 0;}

					printf("-1");
//	printf("%d %d",a,b);
return 0;
}


#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int l[10001],r[10001],y[10001],yy[10001];
main()
{
					int n,i,k=0,a=1;

					scanf("%d",&n);

					for(i=1; i<=n; i++)
					{scanf("%d %d",&l[i],&r[i]);
						y[a]=r[i]-l[i]; yy[a]=r[i]-l[i]; a++;
					} a--;

					sort(y+1,y+a+1);

//					for(i=1; i<=a; i++) printf("%d ",y[i]); printf("\n\n");

					if(y[a]==y[a-1]) {printf("-1"); return 0;}

					for(i=1; i<=a; i++)
					{
						if(yy[i]==y[a]) {printf("%d",i); break;}
					}
return 0;
}


#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int l[100],r[100];
main()
{
                    int n,i,k=0,a=0;

                    scanf("%d",&n);

                    for(i=1; i<=n; i++)
                    {scanf("%d %d",&l[i],&r[i]);
                        if(fabs(r[i]-l[i])>k) {k=fabs(r[i]-l[i]); a=i;}
                    }
                    if(a==0) {printf("-1"); return 0;}

                    printf("%d",a);
return 0;
}


#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
unsigned int l[100001],r[100001];
main()
{//					freopen("input.txt","r",stdin);
//					freopen("output.txt","w",stdout);

					unsigned int n,i,a,b;

					scanf("%u",&n); b++; b--;

					for(i=1; i<=n; i++)
					scanf("%u %u",&l[i],&r[i]);

					sort(l+1,l+n+1); sort(r+1,r+n+1); a=l[1]; b=r[n];

					for(i=1; i<=n; i++)
					if(a==l[i] && b==r[i]) {printf("%u",i); return 0;}

					printf("-1");
//	printf("%d %d",a,b);
return 0;
}


#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
unsigned int l[100001],r[100001];
main()
{//					freopen("input.txt","r",stdin);
//					freopen("output.txt","w",stdout);

					unsigned int n,i,a=100001,b=0;

					scanf("%u",&n); b++; b--;

					for(i=1; i<=n; i++)
					{
						scanf("%u %u",&l[i],&r[i]);

						if(l[i]<a) a=l[i];
						if(r[i]>b) b=r[i];
					}

					for(i=1; i<=n; i++)
					if(a==l[i] && b==r[i]) {printf("%u",i); return 0;}

					printf("-1");
//	printf("%d %d",a,b);
return 0;
}


#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
unsigned int l[100001],r[100001];
main()
{//					freopen("input.txt","r",stdin);
//					freopen("output.txt","w",stdout);

					unsigned int n,i,a=100001,b=0;

					scanf("%u",&n);

					for(i=1; i<=n; i++)
					{
						scanf("%u %u",&l[i],&r[i]);

						if(l[i]<a) a=l[i];
						if(r[i]>b) b=r[i];
					}

					for(i=1; i<=n; i++)
					if(a==l[i] && b==r[i]) {printf("%u",i); return 0;}

					printf("-1");
//	printf("%d %d",a,b);
return 0;
}


#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int l[100],r[100];
main()
{
					int n,i,k=0,a;

					scanf("%d",&n);

					for(i=1; i<=n; i++)
					{scanf("%d %d",&l[i],&r[i]);
						if(fabs(r[i]-l[i])>k) {k=fabs(r[i]-l[i]); a=i;}
					}
					if(a==0) {printf("-1"); return 0;}

					printf("%d",a);
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define V vector
#define S string
#define pb push_back
#define pf push_front
#define sz size()
#define get cin>>
#define print cout<<
#define OO 1e6
#define set(a,b) memset(a,b,sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pii pair<int,int>
#define getArr(ar,n) for(int i=0;i<n;get ar[i++])
#define printArr(ar,n) for(int i=0;i<n;print ar[i++]<<' ')
#define Sort(ar,n) sort(ar,ar+n)
#define getPoint(x,y) get x>>y
#define dist(x1,y1,x2,y2) (x1-x2)*(x1-x2) + ((y1-y2)*(y1-y2))
typedef long long ll;
typedef unsigned long long ull;
int main(){
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n; get n; deque<int>ar;
    for(int i=0;i<n;i++){int x; get x; ar.pb(x);}
    int b=-1;
    for(int i=0;i<n-1;i++)if(ar[i]<=ar[i+1])b=i+1;
    if(b==!-1)print n-1;
    else if(b==n-1){print 0;}
    else {
        int mn = n-b-1;
        int ans =mn;
        while (mn--){
            ar.pf(ar.back()); ar.pop_back();
        }
        for(int i=0;i<n-1;i++){
            if(ar[i]>ar[i+1]){print -1; return 0;}
        }print mn;
    }
}
/*
*/


#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define V vector
#define S string
#define pb push_back
#define pf push_front
#define sz size()
#define get cin>>
#define print cout<<
#define OO 1e6
#define set(a,b) memset(a,b,sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pii pair<int,int>
#define getArr(ar,n) for(int i=0;i<n;get ar[i++])
#define printArr(ar,n) for(int i=0;i<n;print ar[i++]<<' ')
#define Sort(ar,n) sort(ar,ar+n)
#define getPoint(x,y) get x>>y
#define dist(x1,y1,x2,y2) (x1-x2)*(x1-x2) + ((y1-y2)*(y1-y2))
typedef long long ll;
typedef unsigned long long ull;
int main(){
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n; get n; deque<int>ar;
    for(int i=0;i<n;i++){int x; get x; ar.pb(x);}
    int b=-1;
    for(int i=0;i<n-1;i++)if(ar[i]<=ar[i+1])b=i+1;
    if(b==-1)print n-1;
    else if(b==n-1){print 0;}
    else {
        int mn = n-b-1;
        int ans =mn;
        while (mn--){
            ar.pf(ar.back()); ar.pop_back();
        }
        for(int i=0;i<n-1;i++){
            if(ar[i]>ar[i+1]){print -1; return 0;}
        }print mn;
    }
}
/*
*/


#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define V vector
#define S string
#define pb push_back
#define pf push_front
#define sz size()
#define get cin>>
#define print cout<<
#define OO 1e6
#define set(a,b) memset(a,b,sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pii pair<int,int>
#define getArr(ar,n) for(int i=0;i<n;get ar[i++])
#define printArr(ar,n) for(int i=0;i<n;print ar[i++]<<' ')
#define Sort(ar,n) sort(ar,ar+n)
#define getPoint(x,y) get x>>y
#define dist(x1,y1,x2,y2) (x1-x2)*(x1-x2) + ((y1-y2)*(y1-y2))
typedef long long ll;
typedef unsigned long long ull;
int main(){
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n; get n; deque<int>ar;
    for(int i=0;i<n;i++){int x; get x; ar.pb(x);}
    int i=0,nonDec=0,dec=0;
    for(;i<n-1&&ar[i]<=ar[i+1];i++)nonDec++;
    if(nonDec)nonDec++;
    if(i)i++;
    if (i!=n)dec++;
    for(;i<n-1&&ar[i]>=ar[i+1];i++)dec++;
    if(dec+nonDec!=n){print -1; return 0;}
    if(dec==n){print n-1; return 0; }
    int ans =dec;
    while (dec--){
        int x = ar.back();
        ar.pf(x); ar.pop_back();
    }
    for(int i=0;i<n-1;i++){
        if(ar[i]>ar[i+1]){print -1; return 0;}
    }print ans;
}
/*
*/


#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define V vector
#define S string
#define pb push_back
#define sz size()
#define get cin>>
#define print cout<<
#define OO 1e6
#define set(a,b) memset(a,b,sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pii pair<int,int>
#define getArr(ar,n) for(int i=0;i<n;get ar[i++])
#define printArr(ar,n) for(int i=0;i<n;print ar[i++]<<' ')
#define Sort(ar,n) sort(ar,ar+n)
#define getPoint(x,y) get x>>y
#define dist(x1,y1,x2,y2) (x1-x2)*(x1-x2) + ((y1-y2)*(y1-y2))
typedef long long ll;
typedef unsigned long long ull;
int main(){
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n; get n; deque<int>ar; getArr(ar,n);
    int i=0,nonDec=0,dec=0;
    for(;i<n-1&&ar[i]<=ar[i+1];i++)nonDec++;
    if(nonDec)nonDec++;
    if(i)i++;
    if (i!=n)dec++;
    for(;i<n-1&&ar[i]>=ar[i+1];i++)dec++;
    if(dec+nonDec!=n){print -1; return 0;}
    if(dec==n){print n-1; return 0; }
    int ans =dec;
    while (dec--){
        int x = ar[n-1]; ar.pop_back();
        ar.push_front(x);
    }
    for(int i=0;i<n-1;i++){
        if(ar[i]>ar[i+1]){print -1; return 0;}
    }print ans;
}
/*
*/


#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define V vector
#define S string
#define pb push_back
#define pf push_front
#define sz size()
#define get cin>>
#define print cout<<
#define OO 1e6
#define set(a,b) memset(a,b,sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pii pair<int,int>
#define getArr(ar,n) for(int i=0;i<n;get ar[i++])
#define printArr(ar,n) for(int i=0;i<n;print ar[i++]<<' ')
#define Sort(ar,n) sort(ar,ar+n)
#define getPoint(x,y) get x>>y
#define dist(x1,y1,x2,y2) (x1-x2)*(x1-x2) + ((y1-y2)*(y1-y2))
typedef long long ll;
typedef unsigned long long ull;
int main(){
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n; get n; deque<int>ar;
    for(int i=0;i<n;i++){int x; get x; ar.pb(x);}
    int b=-1;
    for(int i=0;i<n-1;i++)if(ar[i]<=ar[i+1])b=i+1;
    if(b==-1)print n-1;
    else if(b==n-1){print 0;}
    else {
        int mn = n-b-1;
        int ans =mn;
        while (mn--){
            ar.pf(ar.back()); ar.pop_back();
        }
        for(int i=0;i<n-1;i++){
            if(ar[i]>ar[i+1]){print -1; return 0;}
        }print ans;
    }
}
/*
*/


#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define V vector
#define S string
#define pb push_back
#define sz size()
#define get cin>>
#define print cout<<
#define OO 1e6
#define set(a,b) memset(a,b,sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pii pair<int,int>
#define getArr(ar,n) for(int i=0;i<n;get ar[i++])
#define printArr(ar,n) for(int i=0;i<n;print ar[i++]<<' ')
#define Sort(ar,n) sort(ar,ar+n)
#define getPoint(x,y) get x>>y
#define dist(x1,y1,x2,y2) (x1-x2)*(x1-x2) + ((y1-y2)*(y1-y2))
typedef long long ll;
typedef unsigned long long ull;
int main(){
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n; get n; int ar[n]; getArr(ar,n);
    int i=0,nonDec=0,dec=0;
    for(;i<n-1&&ar[i]<=ar[i+1];i++)nonDec++;
    if(nonDec)nonDec++;
    if(i)i++;
    for(;i<n-1&&ar[i]>=ar[i+1];i++)dec++;
    if(dec)dec++;
    if(dec==n&&!nonDec)print --dec;
    else print (dec+nonDec==n?dec:-1);
}
/*
*/


#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define V vector
#define S string
#define pb push_back
#define sz size()
#define get cin>>
#define print cout<<
#define OO 1e6
#define set(a,b) memset(a,b,sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pii pair<int,int>
#define getArr(ar,n) for(int i=0;i<n;get ar[i++])
#define printArr(ar,n) for(int i=0;i<n;print ar[i++]<<' ')
#define Sort(ar,n) sort(ar,ar+n)
#define getPoint(x,y) get x>>y
#define dist(x1,y1,x2,y2) (x1-x2)*(x1-x2) + ((y1-y2)*(y1-y2))
typedef long long ll;
typedef unsigned long long ull;
int main(){
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n; get n; int ar[n]; getArr(ar,n);
    int i=0,nonDec=0,dec=0;
    for(;i<n-1&&ar[i]<=ar[i+1];i++)nonDec++;
    if(nonDec)nonDec++;
    if(i)i++;
    if (i!=n)dec++;
    for(;i<n-1&&ar[i]>=ar[i+1];i++)dec++;
    //if(dec)dec++;
    if(dec==n&&!nonDec)print --dec;
    else print (dec+nonDec==n?dec:-1);
}
/*
*/


#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define V vector
#define S string
#define pb push_back
#define pf push_front
#define sz size()
#define get cin>>
#define print cout<<
#define OO 1e6
#define set(a,b) memset(a,b,sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pii pair<int,int>
#define getArr(ar,n) for(int i=0;i<n;get ar[i++])
#define printArr(ar,n) for(int i=0;i<n;print ar[i++]<<' ')
#define Sort(ar,n) sort(ar,ar+n)
#define getPoint(x,y) get x>>y
#define dist(x1,y1,x2,y2) (x1-x2)*(x1-x2) + ((y1-y2)*(y1-y2))
typedef long long ll;
typedef unsigned long long ull;
int main(){
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n; get n; deque<int>ar;
    for(int i=0;i<n;i++){int x; get x; ar.pb(x);}
    int nonDec=1,dec=1;
    for(int i=0;i<n-1;i++){
        if(ar[i]>=ar[i+1])dec++;
        else {
            if(dec>1)break;
        }
    }
    for(int i=0;i<n-1;i++){
        if(ar[i]<=ar[i+1])nonDec++;
        else {
            if(nonDec>1)break;
        }
    }
    if(nonDec==n){print 0; return 0;}
    if(dec==n){print n-1; return 0;}
    //if(dec+nonDec!=n){print -1; return 0;}
    int mn = min(dec,nonDec);
    int ans = mn;
    while (mn--){
        int x = ar.back();
        ar.pf(x); ar.pop_back();
    }
    for(int i=0;i<n-1;i++){
        if(ar[i]>ar[i+1]){print -1; return 0;}
    }print ans;
}
/*
*/