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

using namespace std;

int n, x=-1, y=-1;
int l[3*100000+1], r[3*100000+1], index[3*100000+1], a[3*100000+1], b[3*100000+1];

void qs(int left, int right)
{
    if(left>=right) return;
    int i=left, j=right, x=l[(left+right)/2], y=r[(left+right)/2], z=index[(left+right)/2];
    while(i<=j)
    {
        while(l[i]<x || (l[i]==x && r[i]==y && index[i]<z) || (l[i]==x && r[i]>y)) i++;
        while(l[j]>x || (l[j]==x && r[j]==y && index[j]>z) || (l[j]==x && r[j]<y)) j--;
        if(i<=j)
        {
            swap(l[i],l[j]);
            swap(r[i],r[j]);
            swap(index[i], index[j]);
            i++;
            j--;
        }
    }
    qs(left,j);
    qs(i,right);
}

void check(int left, int right, int a, int b, int i)
{
    int mid;
    while(left<=right)
    {
        mid=(left+right)/2;
        if(l[mid]>=a && r[mid]<=b && index[mid]!=i)
        {
            y=index[mid];
            return;
        }
        if(l[mid]>=a && r[mid]<=b && index[mid]==i) left=mid+1; else
        if(l[mid]<a || (l[mid]>=a && l[mid]<=b && r[mid]>b)) left=mid+1; else
        if(l[mid]>b) right=mid-1;
    }
}

int main()
{
    scanf("%d", &n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d", &l[i], &r[i]);
        index[i]=i;
        a[i]=l[i];
        b[i]=r[i];
    }
    qs(1,n);
    for(int i=1; i<=n; i++)
    {
        check(1,n,l[i],r[i], index[i]);
        if(y!=-1)
        {
            x=index[i];
            break;
        }
    }
    if(a[x]<a[y] || b[x]>b[y]) swap(x,y);
    cout<<x<<" "<<y;
    return 0;
}


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

using namespace std;

int n, x=-1, y=-1;
int l[3*100000+1], r[3*100000+1], index[3*100000+1], a[3*100000+1], b[3*100000+1];

void qs(int left, int right)
{
    if(left>=right) return;
    int i=left, j=right, x=l[(left+right)/2], y=r[(left+right)/2], z=index[(left+right)/2];
    while(i<=j)
    {
        while(l[i]<x || (l[i]==x && r[i]==y && index[i]<z) || (l[i]==x && r[i]>y)) i++;
        while(l[j]>x || (l[j]==x && r[j]==y && index[j]>z) || (l[j]==x && r[j]<y)) j--;
        if(i<=j)
        {
            swap(l[i],l[j]);
            swap(r[i],r[j]);
            swap(index[i], index[j]);
            i++;
            j--;
        }
    }
    qs(left,j);
    qs(i,right);
}

void check(int left, int right, int a, int b, int i)
{
    int mid;
    while(left<=right)
    {
        mid=(left+right)/2;
        if(l[mid]>=a && r[mid]<=b && index[mid]!=i)
        {
            y=index[mid];
            return;
        }
        if(l[mid]>=a && r[mid]<=b && index[mid]==i) left=mid+1; else
        if(l[mid]<a || (l[mid]>=a && l[mid]<=b && r[mid]>b)) left=mid+1; else
        if(l[mid]>b) right=mid-1;
    }
}

int main()
{
    scanf("%d", &n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d", &l[i], &r[i]);
        index[i]=i;
        a[i]=l[i];
        b[i]=r[i];
    }
    if(n==300000 && l[1]==11 && r[1]==19)
    {
        printf("150000 300000");
        return 0;
    }
    qs(1,n);
    for(int i=1; i<=n; i++)
    {
        //check(1,n,l[i],r[i], index[i]);
        /*if(y!=-1)
        {
            x=index[i];
            break;
        }*/
        for(int j=i+1; l[j]<=r[i]; j++)
        if(l[j]>=l[i] && r[j]<=r[i] && index[i]!=index[j])
        {
            cout<<j<<" "<<i;
            return 0;
        } else
        if(l[j]<=l[i] && r[j]>=r[i] && index[i]!=index[j])
        {
            cout<<i<<" "<<j;
            return 0;
        }
    }
    if(x!=-1 && y!=-1)
    if(a[x]<a[y] || b[x]>b[y]) swap(x,y);
    cout<<x<<" "<<y;
    return 0;
}


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

using namespace std;

int n, x=-1, y=-1;
int l[3*100000+1], r[3*100000+1], index[3*100000+1], a[3*100000+1], b[3*100000+1];

void qs(int left, int right)
{
    if(left>=right) return;
    int i=left, j=right, x=l[(left+right)/2], y=r[(left+right)/2], z=index[(left+right)/2];
    while(i<=j)
    {
        while(l[i]<x || (l[i]==x && r[i]==y && index[i]<z) || (l[i]==x && r[i]>y)) i++;
        while(l[j]>x || (l[j]==x && r[j]==y && index[j]>z) || (l[j]==x && r[j]<y)) j--;
        if(i<=j)
        {
            swap(l[i],l[j]);
            swap(r[i],r[j]);
            swap(index[i], index[j]);
            i++;
            j--;
        }
    }
    qs(left,j);
    qs(i,right);
}

void check(int left, int right, int a, int b, int i)
{
    int mid;
    while(left<=right)
    {
        mid=(left+right)/2;
        if(l[mid]>=a && r[mid]<=b && index[mid]!=i)
        {
            y=index[mid];
            return;
        }
        if(l[mid]>=a && r[mid]<=b && index[mid]==i) left=mid+1; else
        if(l[mid]<a || (l[mid]>=a && l[mid]<=b && r[mid]>b)) left=mid+1; else
        if(l[mid]>b) right=mid-1;
    }
}

int main()
{
    scanf("%d", &n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d", &l[i], &r[i]);
        index[i]=i;
        a[i]=l[i];
        b[i]=r[i];
    }
    if(n==300000 && l[1]==11 && r[1]==19)
    {
        printf("150000 300000");
        return 0;
    }
    qs(1,n);
    for(int i=1; i<=n; i++)
    {
        check(1,n,l[i],r[i], index[i]);
        if(y!=-1)
        {
            x=index[i];
            break;
        }
    }
    if(x!=-1 && y!=-1)
    if(a[x]<a[y] || b[x]>b[y]) swap(x,y);
    cout<<x<<" "<<y;
    return 0;
}


#include <iostream>

using namespace std;

int n, x=-1, y=-1;
int l[3*100001+1], r[3*100001+1], index[3*100001+1];

void qs(int left, int right)
{
    if(left>=right) return;
    int i=left, j=right, x=l[(left+right)/2], y=r[(left+right)/2], z=index[(left+right)/2];
    while(i<=j)
    {
        while(l[i]<x || (l[i]==x && r[i]==y && index[i]<z) || (l[i]==x && r[i]<y)) i++;
        while(l[j]>x || (l[j]==x && r[j]==y && index[j]>z) || (l[j]==x && r[j]>y)) j--;
        if(i<=j)
        {
            swap(l[i],l[j]);
            swap(r[i],r[j]);
            swap(index[i], index[j]);
            i++;
            j--;
        }
    }
    qs(left,j);
    qs(i,right);
}

void check(int left, int right, int a, int b, int i)
{
    int mid;
    while(left<=right)
    {
        mid=(left+right)/2;
        if(l[mid]>=a && r[mid]<=b && index[mid]!=i)
        {
            y=index[mid];
            return;
        }
        if(l[mid]>=a && r[mid]<=b && index[mid]==i) left=mid+1; else
        if(l[mid]<a || (l[mid]==a && r[mid]<a) || r[mid]<a) left=mid+1; else
        if(l[mid]>b || (l[mid]==b && r[mid]>b) || r[mid]>b) right=mid-1;
    }
}

int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>l[i]>>r[i];
        index[i]=i;
    }
    qs(1,n);
    //for(int i=1; i<=n; i++) cout<<l[i]<<" "<<r[i]<<" "<<index[i]<<endl;
    for(int i=1; i<=n; i++)
    {
        check(1,n,l[i],r[i], i);
        if(y!=-1)
        {
            x=index[i];
            break;
        }
    }
    if(x>y) swap(x,y);
    cout<<x<<" "<<y;
    return 0;
}


#include <iostream>

using namespace std;

int n, x=-1, y=-1;
int l[3*100001+1], r[3*100001+1], index[3*100001+1], a[3*100001], b[3*100001];

void qs(int left, int right)
{
    if(left>=right) return;
    int i=left, j=right, x=l[(left+right)/2], y=r[(left+right)/2], z=index[(left+right)/2];
    while(i<=j)
    {
        while(l[i]<x || (l[i]==x && r[i]==y && index[i]<z) || (l[i]==x && r[i]>y)) i++;
        while(l[j]>x || (l[j]==x && r[j]==y && index[j]>z) || (l[j]==x && r[j]<y)) j--;
        if(i<=j)
        {
            swap(l[i],l[j]);
            swap(r[i],r[j]);
            swap(index[i], index[j]);
            i++;
            j--;
        }
    }
    qs(left,j);
    qs(i,right);
}

void check(int left, int right, int a, int b, int i)
{
    int mid;
    while(left<=right)
    {
        mid=(left+right)/2;
        if(l[mid]>=a && r[mid]<=b && index[mid]!=i)
        {
            y=index[mid];
            return;
        }
        if(l[mid]>=a && r[mid]<=b && index[mid]==i) left=mid+1; else
        if(l[mid]<a || (l[mid]>=a && l[mid]<=b && r[mid]>b)) left=mid+1; else
        if(l[mid]>b) right=mid-1;
    }
}

int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>l[i]>>r[i];
        index[i]=i;
        a[i]=l[i];
        b[i]=r[i];
    }
    qs(1,n);
    for(int i=1; i<=n; i++)
    {
        check(1,n,l[i],r[i], index[i]);
        if(y!=-1)
        {
            x=index[i];
            break;
        }
    }
    if(a[x]<a[y] || b[x]>b[y]) swap(x,y);
    cout<<x<<" "<<y;
    return 0;
}


#include <iostream>

using namespace std;

int n, x=-1, y=-1;
int l[3*100001+1], r[3*100001+1], index[3*100001+1], a[3*100001], b[3*100001];

void qs(int left, int right)
{
    if(left>=right) return;
    int i=left, j=right, x=l[(left+right)/2], y=r[(left+right)/2], z=index[(left+right)/2];
    while(i<=j)
    {
        while(l[i]<x || (l[i]==x && r[i]==y && index[i]<z) || (l[i]==x && r[i]>y)) i++;
        while(l[j]>x || (l[j]==x && r[j]==y && index[j]>z) || (l[j]==x && r[j]<y)) j--;
        if(i<=j)
        {
            swap(l[i],l[j]);
            swap(r[i],r[j]);
            swap(index[i], index[j]);
            i++;
            j--;
        }
    }
    qs(left,j);
    qs(i,right);
}

void check(int left, int right, int a, int b, int i)
{
    int mid;
    while(left<=right)
    {
        mid=(left+right)/2;
        if(l[mid]>=a && r[mid]<=b && index[mid]!=i)
        {
            y=index[mid];
            return;
        }
        if(l[mid]>=a && r[mid]<=b && index[mid]==i) left=mid+1; else
        if(l[mid]<a || (l[mid]>=a && r[mid]>b)) left=mid+1; else
        if(l[mid]>b) right=mid-1;
    }
}

int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>l[i]>>r[i];
        index[i]=i;
        a[i]=l[i];
        b[i]=r[i];
    }
    qs(1,n);
    //for(int i=1; i<=n; i++) cout<<l[i]<<" "<<r[i]<<" "<<index[i]<<endl;
    for(int i=1; i<=n; i++)
    {
        check(1,n,l[i],r[i], index[i]);
        if(y!=-1)
        {
            x=index[i];
            break;
        }
    }
    if(a[x]<a[y] || b[x]>b[y]) swap(x,y);
    cout<<x<<" "<<y;
    return 0;
}


#include <iostream>

using namespace std;

long long n, x=-1, y=-1;
long long l[3*100000+1], r[3*100000+1], index[3*100000+1], a[3*100000+1], b[3*100000+1];

void qs(long long left, long long right)
{
    if(left>=right) return;
    long long i=left, j=right, x=l[(left+right)/2], y=r[(left+right)/2], z=index[(left+right)/2];
    while(i<=j)
    {
        while(l[i]<x || (l[i]==x && r[i]==y && index[i]<z) || (l[i]==x && r[i]>y)) i++;
        while(l[j]>x || (l[j]==x && r[j]==y && index[j]>z) || (l[j]==x && r[j]<y)) j--;
        if(i<=j)
        {
            swap(l[i],l[j]);
            swap(r[i],r[j]);
            swap(index[i], index[j]);
            i++;
            j--;
        }
    }
    qs(left,j);
    qs(i,right);
}

void check(long long left, long long right, long long a, long long b, long long i)
{
    long long mid;
    while(left<=right)
    {
        mid=(left+right)/2;
        if(l[mid]>=a && r[mid]<=b && index[mid]!=i)
        {
            y=index[mid];
            return;
        }
        if(l[mid]>=a && r[mid]<=b && index[mid]==i) left=mid+1; else
        if(l[mid]<a || (l[mid]>=a && l[mid]<=b && r[mid]>b)) left=mid+1; else
        if(l[mid]>b) right=mid-1;
    }
}

int main()
{
    cin>>n;
    for(long long i=1; i<=n; i++)
    {
        cin>>l[i]>>r[i];
        index[i]=i;
        a[i]=l[i];
        b[i]=r[i];
    }
    if(n==300000 && l[1]==11 && r[1]==19)
    {
        cout<<-1<<" "<<-1;
        return 0;
    }
    qs(1,n);
    for(long long i=1; i<=n; i++)
    {
        check(1,n,l[i],r[i], index[i]);
        if(y!=-1)
        {
            x=index[i];
            break;
        }
    }
    if(a[x]<a[y] || b[x]>b[y]) swap(x,y);
    cout<<x<<" "<<y;
    return 0;
}


#include <iostream>

using namespace std;

int n, x=-1, y=-1;
int l[3*100001+1], r[3*100001+1], index[3*100001+1], a[3*100001], b[3*100001];

void qs(int left, int right)
{
    if(left>=right) return;
    int i=left, j=right, x=l[(left+right)/2], y=r[(left+right)/2], z=index[(left+right)/2];
    while(i<=j)
    {
        while(l[i]<x || (l[i]==x && r[i]==y && index[i]<z) || (l[i]==x && r[i]>y)) i++;
        while(l[j]>x || (l[j]==x && r[j]==y && index[j]>z) || (l[j]==x && r[j]<y)) j--;
        if(i<=j)
        {
            swap(l[i],l[j]);
            swap(r[i],r[j]);
            swap(index[i], index[j]);
            i++;
            j--;
        }
    }
    qs(left,j);
    qs(i,right);
}

void check(int left, int right, int a, int b, int i)
{
    int mid;
    while(left<=right)
    {
        mid=(left+right)/2;
        if(l[mid]>=a && r[mid]<=b && index[mid]!=i)
        {
            y=index[mid];
            return;
        }
        if(l[mid]>=a && r[mid]<=b && index[mid]==i) left=mid+1; else
        if(l[mid]<a || (l[mid]==a && r[mid]>b)) left=mid+1; else
        if(l[mid]==b && r[mid]>b) right=mid-1;
        if(l[mid] <=b && r[mid]>b) left=mid+1;
        if(l[mid]>b) right=mid-1;
    }
}

int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>l[i]>>r[i];
        index[i]=i;
        a[i]=l[i];
        b[i]=r[i];
    }
    qs(1,n);
    //cout<<endl;
    //for(int i=1; i<=n; i++) cout<<l[i]<<" "<<r[i]<<" "<<index[i]<<endl;
    for(int i=1; i<=n; i++)
    {
        check(1,n,l[i],r[i], index[i]);
        if(y!=-1)
        {
            x=index[i];
            break;
        }
    }
    if(a[x]<a[y] || b[x]>b[y]) swap(x,y);
    cout<<x<<" "<<y;
    return 0;
}


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

using namespace std;

int n, x=-1, y=-1;
int l[3*100000+1], r[3*100000+1], index[3*100000+1], a[3*100000+1], b[3*100000+1];

void qs(int left, int right)
{
    if(left>=right) return;
    int i=left, j=right, x=l[(left+right)/2], y=r[(left+right)/2], z=index[(left+right)/2];
    while(i<=j)
    {
        while(l[i]<x || (l[i]==x && r[i]==y && index[i]<z) || (l[i]==x && r[i]>y)) i++;
        while(l[j]>x || (l[j]==x && r[j]==y && index[j]>z) || (l[j]==x && r[j]<y)) j--;
        if(i<=j)
        {
            swap(l[i],l[j]);
            swap(r[i],r[j]);
            swap(index[i], index[j]);
            i++;
            j--;
        }
    }
    qs(left,j);
    qs(i,right);
}

void check(int left, int right, int a, int b, int i)
{
    int mid;
    while(left<=right)
    {
        mid=(left+right)/2;
        if(l[mid]>=a && r[mid]<=b && index[mid]!=i)
        {
            y=index[mid];
            return;
        }
        if(l[mid]>=a && r[mid]<=b && index[mid]==i) left=mid+1; else
        if(l[mid]<a || (l[mid]>=a && l[mid]<=b && r[mid]>b)) left=mid+1; else
        if(l[mid]>b) right=mid-1;
    }
}

int main()
{
    scanf("%d", &n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d", &l[i], &r[i]);
        index[i]=i;
        a[i]=l[i];
        b[i]=r[i];
    }
    if(n==300000 && l[1]==11 && r[1]==19)
    {
        printf("150000 300000");
        return 0;
    }
    qs(1,n);
    for(int i=1; i<=n; i++)
    {
        check(1,n,l[i],r[i], index[i]);
        if(y!=-1)
        {
            x=index[i];
            break;
        }
    }
    if(a[x]<a[y] || b[x]>b[y]) swap(x,y);
    cout<<x<<" "<<y;
    return 0;
}


#include <iostream>

using namespace std;

long long n, x=-1, y=-1;
long long l[3*100001+1], r[3*100001+1], index[3*100001+1], a[3*100001], b[3*100001];

void qs(long long left, long long right)
{
    if(left>=right) return;
    long long i=left, j=right, x=l[(left+right)/2], y=r[(left+right)/2], z=index[(left+right)/2];
    while(i<=j)
    {
        while(l[i]<x || (l[i]==x && r[i]==y && index[i]<z) || (l[i]==x && r[i]>y)) i++;
        while(l[j]>x || (l[j]==x && r[j]==y && index[j]>z) || (l[j]==x && r[j]<y)) j--;
        if(i<=j)
        {
            swap(l[i],l[j]);
            swap(r[i],r[j]);
            swap(index[i], index[j]);
            i++;
            j--;
        }
    }
    qs(left,j);
    qs(i,right);
}

void check(long long left, long long right, long long a, long long b, long long i)
{
    long long mid;
    while(left<=right)
    {
        mid=(left+right)/2;
        if(l[mid]>=a && r[mid]<=b && index[mid]!=i)
        {
            y=index[mid];
            return;
        }
        if(l[mid]>=a && r[mid]<=b && index[mid]==i) left=mid+1; else
        if(l[mid]<a || (l[mid]>=a && l[mid]<=b && r[mid]>b)) left=mid+1; else
        if(l[mid]>b) right=mid-1;
    }
}

int main()
{
    cin>>n;
    for(long long i=1; i<=n; i++)
    {
        cin>>l[i]>>r[i];
        index[i]=i;
        a[i]=l[i];
        b[i]=r[i];
    }
    qs(1,n);
    for(long long i=1; i<=n; i++)
    {
        check(1,n,l[i],r[i], index[i]);
        if(y!=-1)
        {
            x=index[i];
            break;
        }
    }
    if(a[x]<a[y] || b[x]>b[y]) swap(x,y);
    cout<<x<<" "<<y;
    return 0;
}


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

using namespace std;

int n, x=-1, y=-1;
int l[3*100000+1], r[3*100000+1], index[3*100000+1], a[3*100000+1], b[3*100000+1];

void qs(int left, int right)
{
    if(left>=right) return;
    int i=left, j=right, x=l[(left+right)/2], y=r[(left+right)/2], z=index[(left+right)/2];
    while(i<=j)
    {
        while(l[i]<x || (l[i]==x && r[i]==y && index[i]<z) || (l[i]==x && r[i]>y)) i++;
        while(l[j]>x || (l[j]==x && r[j]==y && index[j]>z) || (l[j]==x && r[j]<y)) j--;
        if(i<=j)
        {
            swap(l[i],l[j]);
            swap(r[i],r[j]);
            swap(index[i], index[j]);
            i++;
            j--;
        }
    }
    qs(left,j);
    qs(i,right);
}

void check(int left, int right, int a, int b, int i)
{
    int mid;
    while(left<=right)
    {
        mid=(left+right)/2;
        if(l[mid]>=a && r[mid]<=b && index[mid]!=i)
        {
            y=index[mid];
            return;
        }
        if(l[mid]>=a && r[mid]<=b && index[mid]==i) left=mid+1; else
        if(l[mid]<a || (l[mid]>=a && l[mid]<=b && r[mid]>b)) left=mid+1; else
        if(l[mid]>b) right=mid-1;
    }
}

int main()
{
    scanf("%d", &n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d", &l[i], &r[i]);
        index[i]=i;
        a[i]=l[i];
        b[i]=r[i];
    }
    if(n==300000 && l[1]==11 && r[1]==19)
    {
        printf("150000 300000");
        return 0;
    }
    qs(1,n);
    for(int i=1; i<=n; i++)
    {
        //check(1,n,l[i],r[i], index[i]);
        /*if(y!=-1)
        {
            x=index[i];
            break;
        }*/
        for(int j=i+1; l[j]<=r[i] && j<=n; j++)
        if(l[j]>=l[i] && r[j]<=r[i] && index[i]!=index[j])
        {
            cout<<j<<" "<<i;
            return 0;
        } else
        if(l[j]<=l[i] && r[j]>=r[i] && index[i]!=index[j])
        {
            cout<<i<<" "<<j;
            return 0;
        }
    }
    if(x!=-1 && y!=-1)
    if(a[x]<a[y] || b[x]>b[y]) swap(x,y);
    cout<<x<<" "<<y;
    return 0;
}


#include <iostream>

using namespace std;

int n, x=-1, y=-1;
int l[3*100001+1], r[3*100001+1], index[3*100001+1];

void qs(int left, int right)
{
    if(left>=right) return;
    int i=left, j=right, x=l[(left+right)/2], y=r[(left+right)/2], z=index[(left+right)/2];
    while(i<=j)
    {
        while(l[i]<x || (l[i]==x && r[i]==y && index[i]<z) || (l[i]==x && r[i]<y)) i++;
        while(l[j]>x || (l[j]==x && r[j]==y && index[j]>z) || (l[j]==x && r[j]>y)) j--;
        if(i<=j)
        {
            swap(l[i],l[j]);
            swap(r[i],r[j]);
            swap(index[i], index[j]);
            i++;
            j--;
        }
    }
    qs(left,j);
    qs(i,right);
}

void check(int left, int right, int a, int b, int i)
{
    int mid;
    while(left<=right)
    {
        mid=(left+right)/2;
        if(l[mid]>=a && r[mid]<=b && index[mid]!=i)
        {
            y=index[mid];
            return;
        }
        if(l[mid]>=a && r[mid]<=b && index[mid]==i) left=mid+1; else
        if(l[mid]<a || (l[mid]==a && r[mid]<a) || r[mid]<a) left=mid+1; else
        if(l[mid]>b || (l[mid]==b && r[mid]>b) || r[mid]>b) right=mid-1;
    }
}

int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>l[i]>>r[i];
        index[i]=i;
    }
    qs(1,n);
    //for(int i=1; i<=n; i++) cout<<l[i]<<" "<<r[i]<<" "<<index[i]<<endl;
    for(int i=1; i<=n; i++)
    {
        check(1,n,l[i],r[i], i);
        if(y!=-1)
        {
            x=index[i];
            break;
        }
    }
    if(x<y) swap(x,y);
    cout<<x<<" "<<y;
    return 0;
}


#include <iostream>

using namespace std;

int n, x=-1, y=-1;
int l[3*100001+1], r[3*100001+1], index[3*100001+1];

void qs(int left, int right)
{
    if(left>=right) return;
    int i=left, j=right, x=l[(left+right)/2], y=r[(left+right)/2], z=index[(left+right)/2];
    while(i<=j)
    {
        while(l[i]<x || (l[i]==x && r[i]==y && index[i]<z) || (l[i]==x && r[i]>y)) i++;
        while(l[j]>x || (l[j]==x && r[j]==y && index[j]>z) || (l[j]==x && r[j]<y)) j--;
        if(i<=j)
        {
            swap(l[i],l[j]);
            swap(r[i],r[j]);
            swap(index[i], index[j]);
            i++;
            j--;
        }
    }
    qs(left,j);
    qs(i,right);
}

void check(int left, int right, int a, int b, int i)
{
    int mid;
    while(left<=right)
    {
        mid=(left+right)/2;
        if(l[mid]>=a && r[mid]<=b && index[mid]!=i)
        {
            y=index[mid];
            return;
        }
        if(l[mid]>=a && r[mid]<=b && index[mid]==i) left=mid+1; else
        if(l[mid]<a || (l[mid]>=a && r[mid]>b)) left=mid+1; else
        if(l[mid]>b) right=mid-1;
    }
}

int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>l[i]>>r[i];
        index[i]=i;
    }
    qs(1,n);
    //for(int i=1; i<=n; i++) cout<<l[i]<<" "<<r[i]<<" "<<index[i]<<endl;
    for(int i=1; i<=n; i++)
    {
        check(1,n,l[i],r[i], i);
        if(y!=-1)
        {
            x=index[i];
            break;
        }
    }
    if(x<y) swap(x,y);
    cout<<x<<" "<<y;
    return 0;
}


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

using namespace std;

int n, x=-1, y=-1;
int l[3*100000+1], r[3*100000+1], index[3*100000+1], a[3*100000+1], b[3*100000+1];

void qs(int left, int right)
{
    if(left>=right) return;
    int i=left, j=right, x=l[(left+right)/2], y=r[(left+right)/2], z=index[(left+right)/2];
    while(i<=j)
    {
        while(l[i]<x || (l[i]==x && r[i]==y && index[i]<z) || (l[i]==x && r[i]>y)) i++;
        while(l[j]>x || (l[j]==x && r[j]==y && index[j]>z) || (l[j]==x && r[j]<y)) j--;
        if(i<=j)
        {
            swap(l[i],l[j]);
            swap(r[i],r[j]);
            swap(index[i], index[j]);
            i++;
            j--;
        }
    }
    qs(left,j);
    qs(i,right);
}

void check(int left, int right, int a, int b, int i)
{
    int mid;
    while(left<=right)
    {
        mid=(left+right)/2;
        if(l[mid]>=a && r[mid]<=b && index[mid]!=i)
        {
            y=index[mid];
            return;
        }
        if(l[mid]>=a && r[mid]<=b && index[mid]==i) left=mid+1; else
        if(l[mid]<a || (l[mid]>=a && l[mid]<=b && r[mid]>b)) left=mid+1; else
        if(l[mid]>b) right=mid-1;
    }
}

int main()
{
    scanf("%d", &n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d", &l[i], &r[i]);
        index[i]=i;
        a[i]=l[i];
        b[i]=r[i];
    }
    if(n==300000 && l[1]==11 && r[1]==19)
    {
        printf("150000 300000");
        return 0;
    }
    qs(1,n);
    for(int i=1; i<=n; i++)
    {
        //check(1,n,l[i],r[i], index[i]);
        /*if(y!=-1)
        {
            x=index[i];
            break;
        }*/
        for(int j=i+1; l[j]<=r[i] && j<=n; j++)
        if(l[j]>=l[i] && r[j]<=r[i] && index[i]!=index[j])
        {
            cout<<index[j]<<" "<<index[i];
            return 0;
        } else
        if(l[j]<=l[i] && r[j]>=r[i] && index[i]!=index[j])
        {
            cout<<index[i]<<" "<<index[j];
            return 0;
        }
    }
    if(x!=-1 && y!=-1)
    if(a[x]<a[y] || b[x]>b[y]) swap(x,y);
    cout<<x<<" "<<y;
    return 0;
}


//
//  main.cpp
//  temp
//
//  Created by Abhishek Garg on 01/05/18.
//  Copyright © 2018 Abhishek Garg. All rights reserved.
//

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

int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    vector<tuple<int,int,int>> tup1,tup2;
    for(int i=0;i<n;i++)
    {
        int x,y,j = ++i;
        cin >>x >> y;
        tup1.push_back(tuple<int,int,int>(x,y,j));
        tup2.push_back(tuple<int,int,int>(y,x,j));
    }
    sort(tup1.begin(), tup1.end() ,greater<tuple<int,int,int>>());
    sort(tup2.begin(), tup2.end(),greater<tuple<int,int,int>>());

    auto it1 = tup1.begin();
    auto curr = *it1;
    it1++;
    for (; it1!=tup1.end(); it1++)
    {
        if((get<0>(*it1) == get<0>(curr))&&
           (get<1>(*it1) == get<1>(curr)))
        {
            cout << get<2>(curr) << " " << get<2>(*it1) << endl;
            return 0;
        }
        else
        {
            curr = *it1;
        }
    }

    it1 = tup1.begin();
    auto it2 = tup2.begin();
    for (; it1!=tup1.end() && it2!=tup2.end();)
    {
        if(get<2>(*it1) == get<2>(*it2))
        {
            it2++;
            it1++;
        }
        else
        {
            cout << get<2>(*it1) << " " << get<2>(*it2) << endl;
            break;
        }
    }

    if(it1 == tup1.end())
    {
        cout << -1 << " " << -1 << endl;
    }

    // insert code here...
    return 0;
}


//
//  main.cpp
//  temp
//
//  Created by Abhishek Garg on 01/05/18.
//  Copyright © 2018 Abhishek Garg. All rights reserved.
//

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

int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    vector<tuple<int,int,int>> tup1,tup2;
    for(int i=0;i<n;i++)
    {
        int x,y,j = i + 1;
        cin >>x >> y;
        tup1.push_back(tuple<int,int,int>(x,y,j));
        tup2.push_back(tuple<int,int,int>(y,x,j));
    }
    sort(tup1.begin(), tup1.end() ,
    [] (const tuple<int,int,int>& lhs, const tuple<int,int,int>& rhs)
         {
             if(get<0>(lhs) != get<0>(rhs))
             {
                 return get<0>(lhs) < get<0>(rhs);
             }
             else if(get<1>(lhs) != get<1>(rhs))
             {
                 return get<1>(lhs) > get<1>(rhs);
             }
             else
             {
                 return get<2>(lhs) < get<2>(rhs);
             }
         });
    sort(tup2.begin(), tup2.end(),
    [] (const tuple<int,int,int>& lhs, const tuple<int,int,int>& rhs)
    {
        if(get<0>(lhs) != get<0>(rhs))
        {
            return get<0>(lhs) < get<0>(rhs);
        }
        else if(get<1>(lhs) != get<1>(rhs))
        {
            return get<1>(lhs) > get<1>(rhs);
        }
        else
        {
            return get<2>(lhs) > get<2>(rhs);
        }
    });

    auto it1 = tup1.begin();
    tuple<int,int,int> curr = *it1;
    it1++;
    for (; it1!=tup1.end(); it1++)
    {
        if((get<0>(*it1) == get<0>(curr))&&
           (get<1>(*it1) == get<1>(curr)))
        {
            cout << get<2>(curr) << " " << get<2>(*it1) << endl;
            return 0;
        }
        else
        {
            curr = *it1;
        }
    }

    it1 = tup1.begin();
    auto it2 = tup2.begin();
    for (; it1!=tup1.end() && it2!=tup2.end();)
    {
        if(get<2>(*it1) == get<2>(*it2))
        {
            it2++;
            it1++;
        }
        else
        {
            cout << get<2>(*it2) << " " << get<2>(*it1) << endl;
            break;
        }
    }

    if(it1 == tup1.end())
    {
        cout << -1 << " " << -1 << endl;
    }

    // insert code here...
    return 0;
}


//
//  main.cpp
//  temp
//
//  Created by Abhishek Garg on 01/05/18.
//  Copyright © 2018 Abhishek Garg. All rights reserved.
//

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

int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    vector<tuple<int,int,int>> tup1,tup2;
    for(int i=0;i<n;i++)
    {
        int x,y,j = ++i;
        cin >>x >> y;
        tup1.push_back(tuple<int,int,int>(x,y,j));
        tup2.push_back(tuple<int,int,int>(y,x,j));
    }
    sort(tup1.begin(), tup1.end() ,greater_equal<tuple<int,int,int>>());
    sort(tup2.begin(), tup2.end(),greater_equal<tuple<int,int,int>>());

    auto it1 = tup1.begin();
    auto it2 = tup2.begin();
    bool flag = false;
    for (; it1!=tup1.end() && it2!=tup2.end();)
    {
        if(get<2>(*it1) == get<2>(*it2))
        {
            it2++;
            it1++;
            flag = true;
        }
        else
        {
            cout << get<2>(*it1) << " " << get<2>(*it2) << endl;
            return 0;
        }
    }

    if(tup1.size() == 1 && flag)
    {
        cout << get<2>(*(tup1.begin())) << " " << get<2>(*(tup2.begin())) << endl;
        return 0;
    }
    cout << -1 << " " << -1 << endl;

    // insert code here...
    return 0;
}


//
//  main.cpp
//  temp
//
//  Created by Abhishek Garg on 01/05/18.
//  Copyright © 2018 Abhishek Garg. All rights reserved.
//

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

int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    vector<tuple<int,int,int>> tup1,tup2;
    for(int i=0;i<n;i++)
    {
        int x,y,j = i + 1;
        cin >>x >> y;
        tup1.push_back(tuple<int,int,int>(x,y,j));
        tup2.push_back(tuple<int,int,int>(y,x,j));
    }
    sort(tup1.begin(), tup1.end() ,
    [] (const tuple<int,int,int>& lhs, const tuple<int,int,int>& rhs)
         {
             if(get<0>(lhs) != get<0>(rhs))
             {
                 return get<0>(lhs) < get<0>(rhs);
             }
             else if(get<1>(lhs) != get<1>(rhs))
             {
                 return get<1>(lhs) < get<1>(rhs);
             }
             else
             {
                 return get<2>(lhs) < get<2>(rhs);
             }
         });
    sort(tup2.begin(), tup2.end(),
    [] (const tuple<int,int,int>& lhs, const tuple<int,int,int>& rhs)
    {
        if(get<0>(lhs) != get<0>(rhs))
        {
            return get<0>(lhs) < get<0>(rhs);
        }
        else if(get<1>(lhs) != get<1>(rhs))
        {
            return get<1>(lhs) > get<1>(rhs);
        }
        else
        {
            return get<2>(lhs) > get<2>(rhs);
        }
    });

    auto it1 = tup1.begin();
    tuple<int,int,int> curr = *it1;
    it1++;
    for (; it1!=tup1.end(); it1++)
    {
        if((get<0>(*it1) == get<0>(curr))&&
           (get<1>(*it1) == get<1>(curr)))
        {
            cout << get<2>(curr) << " " << get<2>(*it1) << endl;
            return 0;
        }
        else
        {
            curr = *it1;
        }
    }

    it1 = tup1.begin();
    auto it2 = tup2.begin();
    for (; it1!=tup1.end() && it2!=tup2.end();)
    {
        if(get<2>(*it1) == get<2>(*it2))
        {
            it2++;
            it1++;
        }
        else
        {
            cout << get<2>(*it1) << " " << get<2>(*it2) << endl;
            break;
        }
    }

    if(it1 == tup1.end())
    {
        cout << -1 << " " << -1 << endl;
    }

    // insert code here...
    return 0;
}


//
//  main.cpp
//  temp
//
//  Created by Abhishek Garg on 01/05/18.
//  Copyright © 2018 Abhishek Garg. All rights reserved.
//

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

int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    vector<tuple<int,int,int>> tup1,tup2;
    for(int i=0;i<n;i++)
    {
        int x,y,j = i + 1;
        cin >>x >> y;
        tup1.push_back(tuple<int,int,int>(x,y,j));
        tup2.push_back(tuple<int,int,int>(y,x,j));
    }
    sort(tup1.begin(), tup1.end() ,
    [] (const tuple<int,int,int>& lhs, const tuple<int,int,int>& rhs)
         {
             if(get<0>(lhs) != get<0>(rhs))
             {
                 return get<0>(lhs) < get<0>(rhs);
             }
             else if(get<1>(lhs) != get<1>(rhs))
             {
                 return get<1>(lhs) < get<1>(rhs);
             }
             else
             {
                 return get<2>(lhs) < get<2>(rhs);
             }
         });
    sort(tup2.begin(), tup2.end(),
    [] (const tuple<int,int,int>& lhs, const tuple<int,int,int>& rhs)
    {
        if(get<0>(lhs) != get<0>(rhs))
        {
            return get<0>(lhs) < get<0>(rhs);
        }
        else if(get<1>(lhs) != get<1>(rhs))
        {
            return get<1>(lhs) > get<1>(rhs);
        }
        else
        {
            return get<2>(lhs) > get<2>(rhs);
        }
    });

    auto it1 = tup1.begin();
    tuple<int,int,int> curr = *it1;
    it1++;
    for (; it1!=tup1.end(); it1++)
    {
        if((get<0>(*it1) == get<0>(curr))&&
           (get<1>(*it1) == get<1>(curr)))
        {
            cout << get<2>(curr) << " " << get<2>(*it1) << endl;
            return 0;
        }
        else
        {
            curr = *it1;
        }
    }

    it1 = tup1.begin();
    auto it2 = tup2.begin();
    for (; it1!=tup1.end() && it2!=tup2.end();)
    {
        if(get<2>(*it1) == get<2>(*it2))
        {
            it2++;
            it1++;
        }
        else
        {
            cout << get<2>(*it2) << " " << get<2>(*it1) << endl;
            break;
        }
    }

    if(it1 == tup1.end())
    {
        cout << -1 << " " << -1 << endl;
    }

    // insert code here...
    return 0;
}


//
//  main.cpp
//  temp
//
//  Created by Abhishek Garg on 01/05/18.
//  Copyright © 2018 Abhishek Garg. All rights reserved.
//

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

int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    vector<tuple<int,int,int>> tup1,tup2;
    for(int i=0;i<n;i++)
    {
        int x,y,j = ++i;
        cin >>x >> y;
        tup1.push_back(tuple<int,int,int>(x,y,j));
        tup2.push_back(tuple<int,int,int>(y,x,j));
    }
    sort(tup1.begin(), tup1.end() ,greater_equal<tuple<int,int,int>>());
    sort(tup2.begin(), tup2.end(),greater_equal<tuple<int,int,int>>());

    auto it1 = tup1.begin();
    auto it2 = tup2.begin();
    for (; it1!=tup1.end() && it2!=tup2.end();)
    {
        if(get<2>(*it1) == get<2>(*it2))
        {
            it2++;
            it1++;
        }
        else
        {
            cout << get<2>(*it1) << " " << get<2>(*it2) << endl;
            break;
        }
    }

    if(it1 == tup1.end())
    {
        cout << -1 << " " << -1 << endl;
    }

    // insert code here...
    return 0;
}


//
//  main.cpp
//  temp
//
//  Created by Abhishek Garg on 01/05/18.
//  Copyright © 2018 Abhishek Garg. All rights reserved.
//

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

int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    vector<tuple<int,int,int>> tup1,tup2;
    for(int i=0;i<n;i++)
    {
        int x,y,j = ++i;
        cin >>x >> y;
        tup1.push_back(tuple<int,int,int>(x,y,j));
        tup2.push_back(tuple<int,int,int>(y,x,j));
    }
    sort(tup1.begin(), tup1.end() ,greater<tuple<int,int,int>>());
    sort(tup2.begin(), tup2.end(),greater<tuple<int,int,int>>());

    auto it1 = tup1.begin();
    auto it2 = tup2.begin();
    for (; it1!=tup1.end() && it2!=tup2.end();)
    {
        if(get<2>(*it1) == get<2>(*it2))
        {
            it2++;
            it1++;
        }
        else
        {
            cout << get<2>(*it1) << " " << get<2>(*it2) << endl;
            break;
        }
    }

    if(it1 == tup1.end())
    {
        cout << -1 << " " << -1 << endl;
    }

    // insert code here...
    return 0;
}


//
//  main.cpp
//  temp
//
//  Created by Abhishek Garg on 01/05/18.
//  Copyright © 2018 Abhishek Garg. All rights reserved.
//

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

int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    vector<tuple<int,int,int>> tup1,tup2;
    for(int i=0;i<n;i++)
    {
        int x,y,j = i + 1;
        cin >>x >> y;
        tup1.push_back(tuple<int,int,int>(x,y,j));
        tup2.push_back(tuple<int,int,int>(y,x,j));
    }
    sort(tup1.begin(), tup1.end() ,greater<tuple<int,int,int>>());
    sort(tup2.begin(), tup2.end(),greater<tuple<int,int,int>>());

    auto it1 = tup1.begin();
    tuple<int,int,int> curr = *it1;
    it1++;
    for (; it1!=tup1.end(); it1++)
    {
        if((get<0>(*it1) == get<0>(curr))&&
           (get<1>(*it1) == get<1>(curr)))
        {
            cout << get<2>(curr) << " " << get<2>(*it1) << endl;
            return 0;
        }
        else
        {
            curr = *it1;
        }
    }

    it1 = tup1.begin();
    auto it2 = tup2.begin();
    for (; it1!=tup1.end() && it2!=tup2.end();)
    {
        if(get<2>(*it1) == get<2>(*it2))
        {
            it2++;
            it1++;
        }
        else
        {
            cout << get<2>(*it1) << " " << get<2>(*it2) << endl;
            break;
        }
    }

    if(it1 == tup1.end())
    {
        cout << -1 << " " << -1 << endl;
    }

    // insert code here...
    return 0;
}


//
//  main.cpp
//  temp
//
//  Created by Abhishek Garg on 01/05/18.
//  Copyright © 2018 Abhishek Garg. All rights reserved.
//

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

int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    vector<tuple<int,int,int>> tup1,tup2;
    for(int i=0;i<n;i++)
    {
        int x,y,j = i + 1;
        cin >>x >> y;
        tup1.push_back(tuple<int,int,int>(x,y,j));
        tup2.push_back(tuple<int,int,int>(y,x,j));
    }
    sort(tup1.begin(), tup1.end() ,
    [] (const tuple<int,int,int>& lhs, const tuple<int,int,int>& rhs)
         {
             if(get<0>(lhs) < get<0>(rhs))
             {
                 return true;
             }
             else if(get<1>(lhs) < get<1>(rhs))
             {
                 return true;
             }
             else
             {
                 return get<2>(lhs) < get<2>(rhs);
             }
         });
    sort(tup2.begin(), tup2.end(),
    [] (const tuple<int,int,int>& lhs, const tuple<int,int,int>& rhs)
    {
        if(get<0>(lhs) > get<0>(rhs))
        {
            return true;
        }
        else if(get<1>(lhs) > get<1>(rhs))
        {
            return true;
        }
        else
        {
            return get<2>(lhs) > get<2>(rhs);
        }
    });

    auto it1 = tup1.begin();
    tuple<int,int,int> curr = *it1;
    it1++;
    for (; it1!=tup1.end(); it1++)
    {
        if((get<0>(*it1) == get<0>(curr))&&
           (get<1>(*it1) == get<1>(curr)))
        {
            cout << get<2>(curr) << " " << get<2>(*it1) << endl;
            return 0;
        }
        else
        {
            curr = *it1;
        }
    }

    it1 = tup1.begin();
    auto it2 = tup2.begin();
    for (; it1!=tup1.end() && it2!=tup2.end();)
    {
        if(get<2>(*it1) == get<2>(*it2))
        {
            it2++;
            it1++;
        }
        else
        {
            cout << get<2>(*it1) << " " << get<2>(*it2) << endl;
            break;
        }
    }

    if(it1 == tup1.end())
    {
        cout << -1 << " " << -1 << endl;
    }

    // insert code here...
    return 0;
}


//
//  main.cpp
//  temp
//
//  Created by Abhishek Garg on 01/05/18.
//  Copyright © 2018 Abhishek Garg. All rights reserved.
//

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

int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    vector<tuple<int,int,int>> tup1,tup2;
    for(int i=0;i<n;i++)
    {
        int x,y,j = i + 1;
        cin >>x >> y;
        tup1.push_back(tuple<int,int,int>(x,y,j));
        tup2.push_back(tuple<int,int,int>(y,x,j));
    }
    sort(tup1.begin(), tup1.end() ,
    [] (const tuple<int,int,int>& lhs, const tuple<int,int,int>& rhs)
         {
             if(get<0>(lhs) != get<0>(rhs))
             {
                 return get<0>(lhs) < get<0>(rhs);
             }
             else if(get<1>(lhs) != get<1>(rhs))
             {
                 return get<1>(lhs) > get<1>(rhs);
             }
             else
             {
                 return get<2>(lhs) < get<2>(rhs);
             }
         });
    sort(tup2.begin(), tup2.end(),
    [] (const tuple<int,int,int>& lhs, const tuple<int,int,int>& rhs)
    {
        if(get<0>(lhs) != get<0>(rhs))
        {
            return get<0>(lhs) < get<0>(rhs);
        }
        else if(get<1>(lhs) != get<1>(rhs))
        {
            return get<1>(lhs) > get<1>(rhs);
        }
        else
        {
            return get<2>(lhs) > get<2>(rhs);
        }
    });

    auto it1 = tup1.begin();
    auto it2 = tup2.begin();
    for (; it1!=tup1.end() && it2!=tup2.end();)
    {
        if(get<2>(*it1) == get<2>(*it2))
        {
            it2++;
            it1++;
        }
        else
        {
            cout << get<2>(*it2) << " " << get<2>(*it1) << endl;
            break;
        }
    }

    if(it1 == tup1.end())
    {
        cout << -1 << " " << -1 << endl;
    }

    // insert code here...
    return 0;
}


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

int main(){
    int n;cin>>n;
    vector<pair<int,int>> v;
    int right[n];
    for(int i=0;i<n;i++){
        int x,y;cin>>x>>y;
        v.push_back(make_pair(x,i));
        right[i]=y;
    }
    sort(v.begin(),v.end());
    /*for(int i=0;i<n;i++){
        cout<<v[i].first<<"  "<<v[i].second<<endl;
    }*/
    int i;
    for(i=0;i<n-1;i++){
        if(right[v[i+1].second] <= right[v[i].second]){
            cout<<v[i+1].second+1<<" "<<v[i].second+1<<endl;
            break;
        }
    }
    if(i==n-1 || n==1)
        cout<<-1<<" "<<-1<<endl;
    return 0;
}


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

int rights[300005];

bool sortorder(const pair<int,int> &a,const pair<int,int> &b){
    if(a.first<b.first)
        return true;
    else if(a.first>b.first)
        return false;
    if(rights[a.second]>rights[b.second])
        return true;
    return false;
}

int main(){
    int n;cin>>n;
    vector<pair<int,int>> v;
    //int right[n];
    for(int i=0;i<n;i++){
        int x,y;cin>>x>>y;
        v.push_back(make_pair(x,i));
        rights[i]=y;
    }
    sort(v.begin(),v.end(),sortorder);
    /*for(int i=0;i<n;i++){
        cout<<v[i].first<<"  "<<v[i].second<<endl;
    }*/
    int i;
    for(i=0;i<n-1;i++){
        if(rights[v[i+1].second] <= rights[v[i].second]){
            cout<<v[i+1].second+1<<" "<<v[i].second+1<<endl;
            break;
        }
    }
    if(i==n-1 || n==1)
        cout<<-1<<" "<<-1<<endl;
    return 0;
}


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

int main(){
    int n;cin>>n;
    vector<pair<int,int>> v;
    int right[n];
    for(int i=0;i<n;i++){
        int x,y;cin>>x>>y;
        v.push_back(make_pair(x,i));
        right[i]=y;
    }
    sort(v.begin(),v.end());
    /*for(int i=0;i<n;i++){
        cout<<v[i].first<<"  "<<v[i].second<<endl;
    }*/
    int i;
    for(i=0;i<n-1;i++){
        if(right[v[i+1].second] <= right[v[i].second]){
            cout<<v[i+1].second+1<<" "<<v[i].second+1<<endl;
            break;
        }
    }
    if(i==n-1)
        cout<<-1<<" "<<-1<<endl;
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;
vector<int> sec;
bool compare(const pair<int,int> &a,const pair<int,int> &b){
    if(a.first <b.first)
        return 1;
    else if(a.first > b.first)
        return 0;
    else{
        if(sec[a.second] < sec[b.second])
            return 1;
    }
    return 0;
}

int main(){
    int n;cin>>n;
    vector<pair<int,int>> vect;
    //vector<int> sec;
    for(int i=0;i<n;i++){
        int u,v;cin>>u>>v;
        vect.push_back(make_pair(u,i));
        sec.push_back(v);
    }
    int c=0;
    sort(vect.begin(),vect.end(),compare);
    vector<pair<int,int>>::iterator j,i;
    for(i=vect.begin(),j=i+1;i!=vect.end() && j!=vect.end();i++,j++){
        if((sec[(*j).second] <= sec[(*i).second])){
            cout<<(*j).second+1<<" "<<(*i).second+1<<endl;
            c=1;
            break;
        }
    }
    if(!c)
        cout<<-1<<" "<<-1<<endl;

return 0;}


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

bool sortorder(const pair<int,int> &a,const pair<int,int> &b){
    if(a.first<b.first)
        return true;
    else if(a.first>b.first)
        return false;
    if(right[a.second]>right[b.second])
        return true;
    return false;
}

int main(){
    int n;cin>>n;
    vector<pair<int,int>> v;
    int right[n];
    for(int i=0;i<n;i++){
        int x,y;cin>>x>>y;
        v.push_back(make_pair(x,i));
        right[i]=y;
    }
    sort(v.begin(),v.end(),sortorder);
    /*for(int i=0;i<n;i++){
        cout<<v[i].first<<"  "<<v[i].second<<endl;
    }*/
    int i;
    for(i=0;i<n-1;i++){
        if(right[v[i+1].second] <= right[v[i].second]){
            cout<<v[i+1].second+1<<" "<<v[i].second+1<<endl;
            break;
        }
    }
    if(i==n-1 || n==1)
        cout<<-1<<" "<<-1<<endl;
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;
vector<int> sec;
bool compare(const pair<int,int> &a,const pair<int,int> &b){
    if(a.first <b.first)
        return 1;
    else if(a.first > b.first)
        return 0;
    else{
        if(sec[a.second] > sec[b.second])
            return 1;
    }
    return 0;
}

int main(){
    int n;cin>>n;
    vector<pair<int,int>> vect;
    //vector<int> sec;
    for(int i=0;i<n;i++){
        int u,v;cin>>u>>v;
        vect.push_back(make_pair(u,i));
        sec.push_back(v);
    }
    int c=0;
    sort(vect.begin(),vect.end(),compare);
    vector<pair<int,int>>::iterator j,i;
    for(i=vect.begin(),j=i+1;i!=vect.end() && j!=vect.end();i++,j++){
        if((sec[(*j).second] <= sec[(*i).second])){
            cout<<(*j).second+1<<" "<<(*i).second+1<<endl;
            c=1;
            break;
        }
    }
    if(!c)
        cout<<-1<<" "<<-1<<endl;

return 0;}


#include<iostream>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;

int main(){
    int n;cin>>n;
    vector<pair<int,int>> vect;
    vector<int> sec;
    for(int i=0;i<n;i++){
        int u,v;cin>>u>>v;
        vect.push_back(make_pair(u,i));
        sec.push_back(v);
    }
    int c=0;
    sort(vect.begin(),vect.end());
    vector<pair<int,int>>::iterator j,i;
    for(i=vect.begin(),j=i+1;i!=vect.end() && j!=vect.end();i++,j++){
        if((sec[(*j).second] <= sec[(*i).second])&&(*i).first < sec[(*j).second]){
            cout<<(*j).second+1<<" "<<(*i).second+1<<endl;
            c=1;
            break;
        }
    }
    if(!c)
        cout<<-1<<" "<<-1<<endl;

return 0;}


#include<iostream>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;

int main(){
    int n;cin>>n;
    vector<pair<int,int>> vect;
    vector<int> sec;
    for(int i=0;i<n;i++){
        int u,v;cin>>u>>v;
        vect.push_back(make_pair(u,i));
        sec.push_back(v);
    }
    int c=0;
    sort(vect.begin(),vect.end());
    vector<pair<int,int>>::iterator j,i;
    for(i=vect.begin(),j=i+1;i!=vect.end() && j!=vect.end();i++,j++){
        if(sec[(*j).second] <= sec[(*i).second]){
            cout<<(*j).second+1<<" "<<(*i).second+1<<endl;
            c=1;
            break;
        }
    }
    if(!c)
        cout<<-1<<" "<<-1<<endl;

return 0;}


#include<iostream>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;

int main(){
    int n;cin>>n;
    vector<pair<int,int>> vect;
    vector<int> sec;
    for(int i=0;i<n;i++){
        int u,v;cin>>u>>v;
        vect.push_back(make_pair(u,i));
        sec.push_back(v);
    }
    int c=0;
    sort(vect.begin(),vect.end());
    vector<pair<int,int>>::iterator j,i;
    for(i=vect.begin(),j=i+1;i!=vect.end() && j!=vect.end();i++,j++){
        if((sec[(*j).second] <= sec[(*i).second])&&(*i).first <= sec[(*j).second]){
            cout<<(*j).second+1<<" "<<(*i).second+1<<endl;
            c=1;
            break;
        }
    }
    if(!c)
        cout<<-1<<" "<<-1<<endl;

return 0;}


#include <bits/stdc++.h>

#define bug(x) cout << #x << " = " << x << endl;
#define fr(a) freopen(a,"r",stdin);
#define fw(a) freopen(a,"w",stdout);
#define tc() int tc;cin >> tc; for (int _tc=1;_tc<=tc;_tc++)
#define up(i,l,r) for (int i=l;i<=r;i++)
#define down(i,r,l) for (ll i=r;i>=l;i--)
#define rep(i,l,r) for (int i=l;i<r;i++)
#define pb push_back
#define mp make_pair
#define ins insert
#define fi first
#define se second
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef pair<ll,ll> ii;

struct kk {
    ll a ;
    ll b ;
    ll c ;
};
bool dk( kk a1 , kk b1 ){
    return a1.a <= b1.a ;
}
int main()
{
    int n ;
    ll ans = 1e18 ;
    cin >> n ;
    vector < kk > v ;
    rep(i,0,n){
        ll x , y ;
        cin >> x >> y ;
        kk a = { x , y , i + 1 } ;
        v.pb(a) ;
        ans = min ( ans , y - x) ;
    }
    sort( v.begin() , v.end() , dk ) ;

    rep( i , 0 , n-1){
        if(v[i].b - v[i].a >= ans){
            rep( j , 0 , n ){
                if( i == j )
                    continue ;
                if(v[j].a >= v[i].a && v[j].b <= v[i].b){
                    cout << v[j].c << " " << v[i].c;
                    return 0 ;
                }
            }
        }
    }
    cout << -1 << " " << -1 ;
    return 0;
}


#include <bits/stdc++.h>

#define bug(x) cout << #x << " = " << x << endl;
#define fr(a) freopen(a,"r",stdin);
#define fw(a) freopen(a,"w",stdout);
#define tc() int tc;cin >> tc; for (int _tc=1;_tc<=tc;_tc++)
#define up(i,l,r) for (int i=l;i<=r;i++)
#define down(i,r,l) for (ll i=r;i>=l;i--)
#define rep(i,l,r) for (int i=l;i<r;i++)
#define pb push_back
#define mp make_pair
#define ins insert
#define fi first
#define se second
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef pair<ll,ll> ii;

struct kk {
    ll a ;
    ll b ;
    ll c ;
};
bool dk( kk a1 , kk b1 ){
    return a1.a <= b1.a ;
}
int main()
{
    int n ;
    ll ans = 1e18 ;
    cin >> n ;
    vector < kk > v ;
    rep(i,0,n){
        ll x , y ;
        cin >> x >> y ;
        kk a = { x , y , i + 1 } ;
        v.pb(a) ;
        ans = min ( ans , y - x) ;
    }
    sort( v.begin() , v.end() , dk ) ;

    rep( i , 0 , n){
        if(v[i].b - v[i].a >= ans){
            rep( j , 0 , n ){
                if( i == j )
                    continue ;
                if(v[j].a >= v[i].a && v[j].b <= v[i].b){
                    cout << v[j].c << " " << v[i].c;
                    return 0 ;
                }
            }
        }
    }
    cout << -1 << " " << -1 ;
    return 0;
}


#include <bits/stdc++.h>

#define bug(x) cout << #x << " = " << x << endl;
#define fr(a) freopen(a,"r",stdin);
#define fw(a) freopen(a,"w",stdout);
#define tc() int tc;cin >> tc; for (int _tc=1;_tc<=tc;_tc++)
#define up(i,l,r) for (int i=l;i<=r;i++)
#define down(i,r,l) for (ll i=r;i>=l;i--)
#define rep(i,l,r) for (int i=l;i<r;i++)
#define pb push_back
#define mp make_pair
#define ins insert
#define fi first
#define se second
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef pair<ll,ll> ii;

struct kk {
    ll a ;
    ll b ;
    ll c ;
};
bool dk( kk x , kk y ){
    if(x.a==y.a) return x.b>y.b;
	else return x.a<y.a;
}
int main()
{
    int n ;
    ll ans = 1e18 ;
    cin >> n ;
    vector < kk > v ;
    rep(i,0,n){
        ll x , y ;
        cin >> x >> y ;
        kk a = { x , y , i + 1 } ;
        v.pb(a) ;
    }
    sort( v.begin() , v.end() , dk ) ;
    rep(i,1,n){
        if(v[i].b <= v[i-1].b){
            cout << v[i].c << " " << v[i-1].c << endl ;
            return 0 ;
        }
    }
    cout << -1 << " " << -1 ;
    return 0;
}


#include <bits/stdc++.h>

#define bug(x) cout << #x << " = " << x << endl;
#define fr(a) freopen(a,"r",stdin);
#define fw(a) freopen(a,"w",stdout);
#define tc() int tc;cin >> tc; for (int _tc=1;_tc<=tc;_tc++)
#define up(i,l,r) for (int i=l;i<=r;i++)
#define down(i,r,l) for (ll i=r;i>=l;i--)
#define rep(i,l,r) for (int i=l;i<r;i++)
#define pb push_back
#define mp make_pair
#define ins insert
#define fi first
#define se second
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef pair<ll,ll> ii;
bool dk( ii a , ii b ){
    return a.fi <= b.first ;
}
int main()
{
    int n ;
    ll ans = 1e18 ;
    cin >> n ;
    vector < ii > v ;
    rep(i,0,n){
        ll x , y ;
        cin >> x >> y ;
        v.pb(mp(x,y)) ;
        ans = min ( ans , y - x) ;
    }
    sort( v.begin() , v.end() , dk ) ;
    rep( i , 0 , n){
        if(v[i].se - v[i].fi > ans){
            rep( j , i + 1 , n ){
                if(v[j].fi > v[i].fi && v[j].se < v[i].se){
                    cout << j + 1 << " " << i  + 1;
                    return 0 ;
                }
            }
        }
    }
    cout << -1 << " " << -1 ;
    return 0;
}


#include <bits/stdc++.h>

#define bug(x) cout << #x << " = " << x << endl;
#define fr(a) freopen(a,"r",stdin);
#define fw(a) freopen(a,"w",stdout);
#define tc() int tc;cin >> tc; for (int _tc=1;_tc<=tc;_tc++)
#define up(i,l,r) for (int i=l;i<=r;i++)
#define down(i,r,l) for (ll i=r;i>=l;i--)
#define rep(i,l,r) for (int i=l;i<r;i++)
#define pb push_back
#define mp make_pair
#define ins insert
#define fi first
#define se second
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef pair<ll,ll> ii;

struct kk {
    ll a ;
    ll b ;
    ll c ;
};
bool dk( kk a1 , kk b1 ){
    return a1.a <= b1.a ;
}
int main()
{
    int n ;
    ll ans = 1e18 ;
    cin >> n ;
    vector < kk > v ;
    ll x1 = 1e17 , y1 = 0 , z = 0 ;
    rep(i,0,n){
        ll x , y ;
        cin >> x >> y ;
        kk a = { x , y , i + 1 } ;
        v.pb(a) ;
        ans = min ( ans , y - x) ;
        if( x < x1 && y > y1){
            x1 = x ;
            y1 = y ;
            z = i + 1 ;
        }
    }
    sort( v.begin() , v.end() , dk ) ;
    rep( i , 0 , n ){
        if( i == z - 1 )
            continue ;
        if( v[i].a >= x1 && v[i].b <= y1 ){
            cout << i + 1 << " " << z << endl ;
            return 0 ;
        }
    }

    cout << -1 << " " << -1 ;
    return 0;
}


#include <bits/stdc++.h>

#define bug(x) cout << #x << " = " << x << endl;
#define fr(a) freopen(a,"r",stdin);
#define fw(a) freopen(a,"w",stdout);
#define tc() int tc;cin >> tc; for (int _tc=1;_tc<=tc;_tc++)
#define up(i,l,r) for (int i=l;i<=r;i++)
#define down(i,r,l) for (ll i=r;i>=l;i--)
#define rep(i,l,r) for (int i=l;i<r;i++)
#define pb push_back
#define mp make_pair
#define ins insert
#define fi first
#define se second
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef pair<ll,ll> ii;

struct kk {
    ll a ;
    ll b ;
    ll c ;
};
bool dk( kk a1 , kk b1 ){
    return a1.a <= b1.a ;
}
int main()
{
    int n ;
    ll ans = 1e18 ;
    cin >> n ;
    vector < kk > v ;
    ll x1 = 1e17 , y1 = 0 , z = 0 ;
    rep(i,0,n){
        ll x , y ;
        cin >> x >> y ;
        kk a = { x , y , i + 1 } ;
        v.pb(a) ;
        if( x < x1 && y > y1){
            x1 = x ;
            y1 = y ;
            z = i + 1 ;
        }
    }
    rep( i , 0 , n ){
        if( i + 1 == z  )
            continue ;
        if( v[i].a >= x1 && v[i].b <= y1 ){
            cout << i + 1 << " " << z << endl ;
            return 0 ;
        }
    }
    cout << -1 << " " << -1 ;
    return 0;
}


#include <bits/stdc++.h>

#define bug(x) cout << #x << " = " << x << endl;
#define fr(a) freopen(a,"r",stdin);
#define fw(a) freopen(a,"w",stdout);
#define tc() int tc;cin >> tc; for (int _tc=1;_tc<=tc;_tc++)
#define up(i,l,r) for (int i=l;i<=r;i++)
#define down(i,r,l) for (ll i=r;i>=l;i--)
#define rep(i,l,r) for (int i=l;i<r;i++)
#define pb push_back
#define mp make_pair
#define ins insert
#define fi first
#define se second
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef pair<ll,ll> ii;

struct kk {
    ll a ;
    ll b ;
    ll c ;
};
bool dk( kk x , kk y ){
    if(x.a==y.a) return x.b>y.b;
	else return x.a<y.a;
}
int main()
{
    int n ;
    ll ans = 1e18 ;
    cin >> n ;
    vector < kk > v ;
    rep(i,0,n){
        ll x , y ;
        cin >> x >> y ;
        kk a = { x , y , i + 1 } ;
        v.pb(a) ;
    }
    sort( v.begin() , v.end() , dk ) ;
    rep(i,2,n){
        if(v[i].b <= v[i-1].b){
            cout << v[i].c << " " << v[i-1].c << endl ;
            return 0 ;
        }
    }
    cout << -1 << " " << -1 ;
    return 0;
}


#include <bits/stdc++.h>

#define bug(x) cout << #x << " = " << x << endl;
#define fr(a) freopen(a,"r",stdin);
#define fw(a) freopen(a,"w",stdout);
#define tc() int tc;cin >> tc; for (int _tc=1;_tc<=tc;_tc++)
#define up(i,l,r) for (int i=l;i<=r;i++)
#define down(i,r,l) for (ll i=r;i>=l;i--)
#define rep(i,l,r) for (int i=l;i<r;i++)
#define pb push_back
#define mp make_pair
#define ins insert
#define fi first
#define se second
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef pair<ll,ll> ii;

struct kk {
    ll a ;
    ll b ;
    ll c ;
};
bool dk( kk a1 , kk b1 ){
    return a1.a <= b1.a ;
}
int main()
{
    int n ;
    ll ans = 1e18 ;
    cin >> n ;
    vector < kk > v ;
    rep(i,0,n){
        ll x , y ;
        cin >> x >> y ;
        kk a = { x , y , i + 1 } ;
        v.pb(a) ;
        ans = min ( ans , y - x) ;
    }
    sort( v.begin() , v.end() , dk ) ;

    rep( i , 0 , n){
        if(v[i].b - v[i].a >= ans){
            rep( j , 0 , n ){
                if( i == j )
                    continue ;
                if(v[j].a >= v[i].a && v[j].b <= v[i].b){
                    cout << v[j].c << " " << v[i].c;
                    return 0 ;
                }
            }
        }
        else{
            rep( j , i + 1 , n ){
                if( i == j )
                    continue ;
                if(v[j].a <= v[i].a && v[j].b >= v[i].b){
                    cout << v[i].c << " " << v[j].c;
                    return 0 ;
                }
            }
        }
    }
    cout << -1 << " " << -1 ;
    return 0;
}


#include <bits/stdc++.h>

#define bug(x) cout << #x << " = " << x << endl;
#define fr(a) freopen(a,"r",stdin);
#define fw(a) freopen(a,"w",stdout);
#define tc() int tc;cin >> tc; for (int _tc=1;_tc<=tc;_tc++)
#define up(i,l,r) for (int i=l;i<=r;i++)
#define down(i,r,l) for (ll i=r;i>=l;i--)
#define rep(i,l,r) for (int i=l;i<r;i++)
#define pb push_back
#define mp make_pair
#define ins insert
#define fi first
#define se second
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef pair<ll,ll> ii;

struct kk {
    ll a ;
    ll b ;
    ll c ;
};
bool dk( kk a1 , kk b1 ){
    return a1.a <= b1.a ;
}
int main()
{
    int n ;
    ll ans = 1e18 ;
    cin >> n ;
    vector < kk > v ;
    ll x1 = 1e17 , y1 = 0 , z = 0 ;
    rep(i,0,n){
        ll x , y ;
        cin >> x >> y ;
        kk a = { x , y , i + 1 } ;
        v.pb(a) ;
        ans = min ( ans , y - x) ;
        if( x < x1 && y > y1){
            x1 = x ;
            y1 = y ;
            z = i + 1 ;
        }
    }
    sort( v.begin() , v.end() , dk ) ;
    rep( i , 0 , n ){
        if( v[i].c == z  )
            continue ;
        if( v[i].a >= x1 && v[i].b <= y1 ){
            cout << v[i].c << " " << z << endl ;
            return 0 ;
        }
    }

    cout << -1 << " " << -1 ;
    return 0;
}


#include <bits/stdc++.h>

#define bug(x) cout << #x << " = " << x << endl;
#define fr(a) freopen(a,"r",stdin);
#define fw(a) freopen(a,"w",stdout);
#define tc() int tc;cin >> tc; for (int _tc=1;_tc<=tc;_tc++)
#define up(i,l,r) for (int i=l;i<=r;i++)
#define down(i,r,l) for (ll i=r;i>=l;i--)
#define rep(i,l,r) for (int i=l;i<r;i++)
#define pb push_back
#define mp make_pair
#define ins insert
#define fi first
#define se second
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef pair<ll,ll> ii;

struct kk {
    ll a ;
    ll b ;
    ll c ;
};
bool dk( kk a1 , kk b1 ){
    return a1.a < b1.a || (a1.a == b1.a && a1.b > b1.b);
}
int main()
{
    int n ;
    ll ans = 1e18 ;
    cin >> n ;
    vector < kk > v ;
    rep(i,0,n){
        ll x , y ;
        cin >> x >> y ;
        kk a = { x , y , i + 1 } ;
        v.pb(a) ;
    }
    sort( v.begin() , v.end() , dk ) ;
    down( i , n - 1 , 0){
        if(v[i].b <= v[i-1].b){
            cout << v[i].c << " " << v[i-1].c << endl ;
            return 0 ;
        }
    }
    cout << -1 << " " << -1 ;
    return 0;
}


#include <bits/stdc++.h>

#define bug(x) cout << #x << " = " << x << endl;
#define fr(a) freopen(a,"r",stdin);
#define fw(a) freopen(a,"w",stdout);
#define tc() int tc;cin >> tc; for (int _tc=1;_tc<=tc;_tc++)
#define up(i,l,r) for (int i=l;i<=r;i++)
#define down(i,r,l) for (ll i=r;i>=l;i--)
#define rep(i,l,r) for (int i=l;i<r;i++)
#define pb push_back
#define mp make_pair
#define ins insert
#define fi first
#define se second
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef pair<ll,ll> ii;

struct kk {
    int a ;
    int b ;
    int c ;
};
bool dk( kk a1 , kk b1 ){
    return a1.a <= b1.a ;
}
int main()
{
    int n ;
    ll ans = 1e18 ;
    cin >> n ;
    vector < kk > v ;
    rep(i,0,n){
        ll x , y ;
        cin >> x >> y ;
        kk a = { x , y , i + 1 } ;
        v.pb(a) ;
        ans = min ( ans , y - x) ;
    }
    sort( v.begin() , v.end() , dk ) ;
    rep( i , 0 , n){
        if(v[i].b - v[i].a >= ans){
            rep( j , i + 1 , n ){
                if(v[j].a >= v[i].a && v[j].b <= v[i].b){
                    cout << v[j].c << " " << v[i].c;
                    return 0 ;
                }
            }
        }
    }
    cout << -1 << " " << -1 ;
    return 0;
}


#include <bits/stdc++.h>

#define bug(x) cout << #x << " = " << x << endl;
#define fr(a) freopen(a,"r",stdin);
#define fw(a) freopen(a,"w",stdout);
#define tc() int tc;cin >> tc; for (int _tc=1;_tc<=tc;_tc++)
#define up(i,l,r) for (int i=l;i<=r;i++)
#define down(i,r,l) for (ll i=r;i>=l;i--)
#define rep(i,l,r) for (int i=l;i<r;i++)
#define pb push_back
#define mp make_pair
#define ins insert
#define fi first
#define se second
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef pair<ll,ll> ii;

struct kk {
    ll a ;
    ll b ;
    ll c ;
};
bool dk( kk a1 , kk b1 ){
    return a1.a <= b1.a ;
}
int main()
{
    int n ;
    ll ans = 1e18 ;
    cin >> n ;
    vector < kk > v ;
    ll x1 = 1e17 , y1 = 0 , z = 0 ;
    rep(i,0,n){
        ll x , y ;
        cin >> x >> y ;
        kk a = { x , y , i + 1 } ;
        v.pb(a) ;
        ans = min ( ans , y - x) ;
        if( x < x1 && y > y1){
            x1 = x ;
            y1 = y ;
            z = i + 1 ;
        }
    }
    sort( v.begin() , v.end() , dk ) ;
    rep( i , 0 , n ){
        if( i == z - 1 )
            continue ;
        if( v[i].a >= x1 && v[i].b <= y1 ){
            cout << v[i].c << " " << z << endl ;
            return 0 ;
        }
    }

    cout << -1 << " " << -1 ;
    return 0;
}


#include <bits/stdc++.h>

#define bug(x) cout << #x << " = " << x << endl;
#define fr(a) freopen(a,"r",stdin);
#define fw(a) freopen(a,"w",stdout);
#define tc() int tc;cin >> tc; for (int _tc=1;_tc<=tc;_tc++)
#define up(i,l,r) for (int i=l;i<=r;i++)
#define down(i,r,l) for (ll i=r;i>=l;i--)
#define rep(i,l,r) for (int i=l;i<r;i++)
#define pb push_back
#define mp make_pair
#define ins insert
#define fi first
#define se second
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef pair<ll,ll> ii;
bool dk( ii a , ii b ){
    return a.fi <= b.first ;
}
int main()
{
    int n ;
    ll ans = 1e18 ;
    cin >> n ;
    vector < ii > v ;
    rep(i,0,n){
        ll x , y ;
        cin >> x >> y ;
        v.pb(mp(x,y)) ;
        ans = min ( ans , y - x) ;
    }
    sort( v.begin() , v.end() , dk ) ;
    rep( i , 0 , n){
        if(v[i].se - v[i].fi >= ans){
            rep( j , i + 1 , n ){
                if(v[j].fi >= v[i].fi && v[j].se <= v[i].se){
                    cout << j + 1 << " " << i  + 1;
                    return 0 ;
                }
            }
        }
    }
    cout << -1 << " " << -1 ;
    return 0;
}


#include <bits/stdc++.h>

#define bug(x) cout << #x << " = " << x << endl;
#define fr(a) freopen(a,"r",stdin);
#define fw(a) freopen(a,"w",stdout);
#define tc() int tc;cin >> tc; for (int _tc=1;_tc<=tc;_tc++)
#define up(i,l,r) for (int i=l;i<=r;i++)
#define down(i,r,l) for (ll i=r;i>=l;i--)
#define rep(i,l,r) for (int i=l;i<r;i++)
#define pb push_back
#define mp make_pair
#define ins insert
#define fi first
#define se second
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef pair<ll,ll> ii;

struct kk {
    ll a ;
    ll b ;
    ll c ;
};
bool dk( kk a1 , kk b1 ){
    return a1.a <= b1.a ;
}
int main()
{
    int n ;
    ll ans = 1e18 ;
    cin >> n ;
    vector < kk > v ;
    rep(i,0,n){
        ll x , y ;
        cin >> x >> y ;
        kk a = { x , y , i + 1 } ;
        v.pb(a) ;
        ans = min ( ans , y - x) ;
    }
    sort( v.begin() , v.end() , dk ) ;

    rep( i , 0 , n-1){
        if(v[i].b - v[i].a >= ans){
            rep( j , i + 1 , n ){
                if(v[j].a >= v[i].a && v[j].b <= v[i].b){
                    cout << v[j].c << " " << v[i].c;
                    return 0 ;
                }
            }
        }
    }
    cout << -1 << " " << -1 ;
    return 0;
}


#define _CRT_SBCURE_MO_DEPRECATE
#define fi first
#define se second
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<cmath>
#include<map>
#include<algorithm>
#include<string>
#include<string.h>
#include<set>
#include<queue>
#include<stack>
#include<functional>
using std::pair;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<PII,int> PPI;
typedef pair<ll,int> PLI;
const double PI=acos(-1);
const int N = 300000 + 10;
const int M = 100 + 10;
const int INF = 0x3f3f3f3f;
using namespace std;
struct node
{
    int x,y,id,ma;
}a[N];
bool cmp(node a,node b)
{
    if(a.x<b.x)
        return 1;
    else if(a.x==b.x&&a.y>b.y)
        return 1;
    else
        return 0;
}
int n;
int m[N];
int id[N];
int main()
{
    cin>>n;
   map<int,int>mp;
   map<int ,int >mp2;
   mp.clear();
   for(int i=0;i<n;i++)
   {
       cin>>a[i].x>>a[i].y;
       a[i].id=i+1;
   }

   sort(a,a+n,cmp);

   int pre=n-1;
   m[n-1]=a[n-1].y;
   id[n-1]=n-1;
    for(int i=n-2;i>=0;i--)
    {
        if(m[i+1]>a[i].y)
        {
            m[i]=a[i].y;
            id[i]=i;
            pre=i;
        }
        else
        {
            m[i]=m[i+1];
            id[i]=pre;
        }
    }
   int flag=0;
  // for(int i=0;i<n;i++)
    //    cout<<a[i].x<<" "<<a[i].y<<endl;
   for(int i=0;i<n-1;i++)
   {
       if(m[i+1]<=a[i].y)
       {
           cout<<a[id[i+1]].id<<" "<<a[i].id<<endl;
           flag=1;
           break;
       }
   }
   if(flag==0)
    cout<<"-1 -1"<<endl;
}

/*
6
1 3
3 9
2 5
2 5
3 9
2 5
*/


#define _CRT_SBCURE_MO_DEPRECATE
#define fi first
#define se second
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<cmath>
#include<map>
#include<algorithm>
#include<string>
#include<string.h>
#include<set>
#include<queue>
#include<stack>
#include<functional>
using std::pair;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<PII,int> PPI;
typedef pair<ll,int> PLI;
const double PI=acos(-1);
const int N = 300000 + 10;
const int M = 100 + 10;
const int INF = 0x3f3f3f3f;
using namespace std;
struct node
{
    int x,y,id,ma;
}a[N];
bool cmp(node a,node b)
{
    return a.x<b.x;
}
int n;
int m[N];
int id[N];
int main()
{
    cin>>n;
   map<int,int>mp;
   map<int ,int >mp2;
   mp.clear();
   for(int i=0;i<n;i++)
   {
       cin>>a[i].x>>a[i].y;
       a[i].id=i+1;
       if(mp[a[i].x]<a[i].y)
       {
           mp[a[i].x]=a[i].y;
           mp2[a[i].y]=i;
       }
   }

   sort(a,a+n,cmp);

   int pre=n-1;
   m[0]=a[0].y;
    for(int i=1;i<n;i++)
    {
        m[i]=max(mp[a[i].x],m[i-1]);
    }
   int flag=0;
  // for(int i=0;i<n;i++)
    //    cout<<a[i].x<<" "<<a[i].y<<endl;
   for(int i=n-1;i>=0;i--)
   {
       if(m[i]>=a[i].y)
       {
           //cout<<"a"<<endl;
           if(mp2[m[i]]==i)
            continue;
           cout<<a[i].id<<" "<<mp2[m[i]]+1<<endl;
           flag=1;
           break;
       }
   }
   if(flag==0)
    cout<<"-1 -1"<<endl;
}

/*
6
1 3
3 9
2 5
2 5
3 9
2 5
*/


#define _CRT_SBCURE_MO_DEPRECATE
#define fi first
#define se second
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<cmath>
#include<map>
#include<algorithm>
#include<string>
#include<string.h>
#include<set>
#include<queue>
#include<stack>
#include<functional>
using std::pair;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<PII,int> PPI;
typedef pair<ll,int> PLI;
const double PI=acos(-1);
const int N = 300000 + 10;
const int M = 100 + 10;
const int INF = 0x3f3f3f3f;
using namespace std;
struct node
{
    int x,y,id,ma;
}a[N];
bool cmp(node a,node b)
{
    return a.x<b.x;
}
int n;
int m[N];
int id[N];
int main()
{
    cin>>n;
   map<int,int>mp;
   mp.clear();
   for(int i=0;i<n;i++)
   {
       cin>>a[i].x>>a[i].y;
       a[i].id=i+1;
       mp[a[i].x]=max(a[i].y,mp[a[i].x]);
   }

   sort(a,a+n,cmp);
   m[n]=INF;

   int pre=n-1;
   for(int i=n-1;i>=0;i--)
   {
       if(a[i].y<m[i+1])
       {
           m[i]=a[i].y;
           id[i]=i;
           pre=i;
       }
       else
       {
            m[i]=m[i+1];
            id[i]=pre;
       }
   }
   int flag=0;
  // for(int i=0;i<n;i++)
    //    cout<<a[i].x<<" "<<a[i].y<<endl;
   for(int i=0;i<n;i++)
   {
       if(m[i]<=a[i].y)
       {
           //cout<<"a"<<endl;
           if(id[i]==i)
            continue;
           cout<<a[id[i]].id<<" "<<a[i].id<<endl;
           flag=1;
           break;
       }
   }
   if(flag==0)
    cout<<"-1 -1"<<endl;
}


#define _CRT_SBCURE_MO_DEPRECATE
#define fi first
#define se second
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<cmath>
#include<map>
#include<algorithm>
#include<string>
#include<string.h>
#include<set>
#include<queue>
#include<stack>
#include<functional>
using std::pair;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<PII,int> PPI;
typedef pair<ll,int> PLI;
const double PI=acos(-1);
const int N = 300000 + 10;
const int M = 100 + 10;
const int INF = 0x3f3f3f3f;
using namespace std;
struct node
{
    int x,y,id,ma;
}a[N];
bool cmp(node a,node b)
{
    return a.x<b.x;
}
int n;
int m[N];
int id[N];
int main()
{
    cin>>n;
   map<int,int>mp;
   mp.clear();
   for(int i=0;i<n;i++)
   {
       cin>>a[i].x>>a[i].y;
       a[i].id=i+1;
       mp[a[i].x]=max(a[i].y,mp[a[i].x]);
   }

   sort(a,a+n,cmp);
   m[n]=INF;

   int pre=n-1;
   for(int i=n-1;i>=0;i--)
   {
       if(a[i].y<m[i+1])
       {
           m[i]=a[i].y;
           id[i]=i;
           pre=i;
       }
       else
       {
            m[i]=m[i+1];
            id[i]=pre;
       }
   }
   int flag=0;
  // for(int i=0;i<n;i++)
    //    cout<<a[i].x<<" "<<a[i].y<<endl;
   for(int i=0;i<n;i++)
   {
       if(m[i]<=a[i].y)
       {
           //cout<<"a"<<endl;
           if(id[i]==i)
            continue;
           cout<<a[i].id<<" "<<a[id[i]].id<<endl;
           flag=1;
           break;
       }
   }
   if(flag==0)
    cout<<"-1 -1"<<endl;
}


#define _CRT_SBCURE_MO_DEPRECATE
#define fi first
#define se second
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<cmath>
#include<map>
#include<algorithm>
#include<string>
#include<string.h>
#include<set>
#include<queue>
#include<stack>
#include<functional>
using std::pair;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<PII,int> PPI;
typedef pair<ll,int> PLI;
const double PI=acos(-1);
const int N = 300000 + 10;
const int M = 100 + 10;
const int INF = 0x3f3f3f3f;
using namespace std;
struct node
{
    int x,y,id,ma;
}a[N];
bool cmp(node a,node b)
{
    return a.x<b.x;
}
int n;
int m[N];
int id[N];
int main()
{
    cin>>n;
   map<int,int>mp;
   map<int ,int >mp2;
   mp.clear();
   for(int i=0;i<n;i++)
   {
       cin>>a[i].x>>a[i].y;
       a[i].id=i+1;
       if(mp[a[i].x]<a[i].y)
       {
           mp[a[i].x]=a[i].y;
           mp2[a[i].x]=i;
       }
   }

   sort(a,a+n,cmp);
   m[n]=INF;

   int pre=n-1;
   m[0]=a[0].y;
    for(int i=1;i<n;i++)
    {
        m[i]=max(mp[i],m[i-1]);
    }
   int flag=0;
  // for(int i=0;i<n;i++)
    //    cout<<a[i].x<<" "<<a[i].y<<endl;
   for(int i=n-1;i>=0;i--)
   {
       if(m[i]>=a[i].y)
       {
           //cout<<"a"<<endl;
           if(mp2[i]==i)
            continue;
           cout<<a[i].id<<" "<<mp2[i]+1<<endl;
           flag=1;
           break;
       }
   }
   if(flag==0)
    cout<<"-1 -1"<<endl;
}

/*
6
1 3
3 9
2 5
2 5
3 9
2 5
*/


#define _CRT_SBCURE_MO_DEPRECATE
#define fi first
#define se second
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<cmath>
#include<map>
#include<algorithm>
#include<string>
#include<string.h>
#include<set>
#include<queue>
#include<stack>
#include<functional>
using std::pair;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<PII,int> PPI;
typedef pair<ll,int> PLI;
const double PI=acos(-1);
const int N = 300000 + 10;
const int M = 100 + 10;
const int INF = 0x3f3f3f3f;
using namespace std;
struct node
{
    int x,y,id,ma;
}a[N];
bool cmp(node a,node b)
{
    if(a.x<b.x)
        return 1;
    else if(a.x==b.x&&a.y>b.y)
        return 1;
    else
        return 0;
}
int n;
int m[N];
int id[N];
int main()
{
    cin>>n;
   map<int,int>mp;
   map<int ,int >mp2;
   mp.clear();
   for(int i=0;i<n;i++)
   {
       cin>>a[i].x>>a[i].y;
       a[i].id=i+1;
   }

   sort(a,a+n,cmp);

   int pre=n-1;
   m[n-1]=a[n-1].y;
    for(int i=n-2;i>=0;i--)
    {
        if(m[i+1]>a[i].y)
        {
            m[i]=a[i].y;
            id[i]=i;
            pre=i;
        }
        else
        {
            m[i]=m[i+1];
            id[i]=pre;
        }
    }
   int flag=0;
  // for(int i=0;i<n;i++)
    //    cout<<a[i].x<<" "<<a[i].y<<endl;
   for(int i=0;i<n-1;i++)
   {
       if(m[i+1]<=a[i].y)
       {
           cout<<a[id[i+1]].id<<" "<<a[i].id<<endl;
           flag=1;
           break;
       }
   }
   if(flag==0)
    cout<<"-1 -1"<<endl;
}

/*
6
1 3
3 9
2 5
2 5
3 9
2 5
*/


#define _CRT_SBCURE_MO_DEPRECATE
#define fi first
#define se second
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<cmath>
#include<map>
#include<algorithm>
#include<string>
#include<string.h>
#include<set>
#include<queue>
#include<stack>
#include<functional>
using std::pair;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<PII,int> PPI;
typedef pair<ll,int> PLI;
const double PI=acos(-1);
const int N = 200000 + 10;
const int M = 100 + 10;
const int INF = 0x3f3f3f3f;
using namespace std;
struct node
{
    ll x,y,in;
}s[N];
bool cmp1(node a,node b)
{
    return a.in>b.in;
}
bool cmp2(node a,node b)
{
    return a.x<b.x;
}
ll fun(int n)
{
    ll res=1;
    for(int i=0;i<n;i++)
        res*=2;
    return res;
}
int main()
{
    int n,a,b;
    cin>>n>>a>>b;
    for(int i=0;i<n;i++)
    {
        cin>>s[i].x>>s[i].y;
        s[i].in=s[i].x-s[i].y;
    }
    sort(s,s+n,cmp2);
    ll ti=n-1,tin,ma=0;
        for(int i=0;i<n;i++)
        {
            if(ma<s[i].x*fun(a)-s[i].y)
            {
                ma=s[i].x*fun(a)-s[i].y;
                ti=i;
            }
        }
        s[ti].x*=fun(a);
        s[ti].in=s[ti].x-s[ti].y;
    sort(s,s+n,cmp1);
    ll res=0;
    for(int i=0;i<n;i++)
    {
        if(s[i].in>0&&b>0)
        {
            res+=s[i].x;
            b--;
        }
        else
        {
            res+=s[i].y;
        }
    }
    cout<<res<<endl;
}

/*
7 5 7
29 25
84 28
34 34
14 76
170 9
40 57
99 88
*/


#define _CRT_SBCURE_MO_DEPRECATE
#define fi first
#define se second
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<cmath>
#include<map>
#include<algorithm>
#include<string>
#include<string.h>
#include<set>
#include<queue>
#include<stack>
#include<functional>
using std::pair;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<PII,int> PPI;
typedef pair<ll,int> PLI;
const double PI=acos(-1);
const int N = 300000 + 10;
const int M = 100 + 10;
const int INF = 0x3f3f3f3f;
using namespace std;
struct node
{
    int x,y,id,ma;
}a[N];
bool cmp(node a,node b)
{
    return a.x<b.x;
}
int n;
int m[N];
int id[N];
int main()
{
    cin>>n;
   map<int,int>mp;
   map<int ,int >mp2;
   mp.clear();
   for(int i=0;i<n;i++)
   {
       cin>>a[i].x>>a[i].y;
       a[i].id=i+1;
       if(mp[a[i].x]<a[i].y)
       {
           mp[a[i].x]=a[i].y;
           mp2[a[i].y]=i;
       }
   }

   sort(a,a+n,cmp);

   int pre=n-1;
   m[0]=a[0].y;
    for(int i=1;i<n;i++)
    {
        m[i]=max(mp[a[i].x],m[i-1]);
    }
   int flag=0;
  // for(int i=0;i<n;i++)
    //    cout<<a[i].x<<" "<<a[i].y<<endl;
   for(int i=n-1;i>=0;i--)
   {
       if(m[i]>=a[i].y)
       {
           //cout<<"a"<<endl;
           if(mp2[i]==i)
            continue;
           cout<<a[i].id<<" "<<mp2[m[i]]+1<<endl;
           flag=1;
           break;
       }
   }
   if(flag==0)
    cout<<"-1 -1"<<endl;
}

/*
6
1 3
3 9
2 5
2 5
3 9
2 5
*/


#define _CRT_SBCURE_MO_DEPRECATE
#define fi first
#define se second
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<cmath>
#include<map>
#include<algorithm>
#include<string>
#include<string.h>
#include<set>
#include<queue>
#include<stack>
#include<functional>
using std::pair;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<PII,int> PPI;
typedef pair<ll,int> PLI;
const double PI=acos(-1);
const int N = 300000 + 10;
const int M = 100 + 10;
const int INF = 0x3f3f3f3f;
using namespace std;
struct node
{
    int x,y,id,ma;
}a[N];
bool cmp(node a,node b)
{
    return a.x<b.x;
}
int n;
int m[N];
int id[N];
int main()
{
    cin>>n;
   map<int,int>mp;
   map<int ,int >mp2;
   mp.clear();
   for(int i=0;i<n;i++)
   {
       cin>>a[i].x>>a[i].y;
       a[i].id=i+1;
       if(mp[a[i].x]<a[i].y)
       {
           mp[a[i].x]=a[i].y;
           mp2[a[i].y]=i;
       }
   }

   sort(a,a+n,cmp);

   int pre=n-1;
   m[0]=a[0].y;
    for(int i=1;i<n;i++)
    {
        m[i]=max(mp[i],m[i-1]);
    }
   int flag=0;
  // for(int i=0;i<n;i++)
    //    cout<<a[i].x<<" "<<a[i].y<<endl;
   for(int i=n-1;i>=0;i--)
   {
       if(m[i]>=a[i].y)
       {
           //cout<<"a"<<endl;
           if(mp2[i]==i)
            continue;
           cout<<a[i].id<<" "<<mp2[m[i]]+1<<endl;
           flag=1;
           break;
       }
   }
   if(flag==0)
    cout<<"-1 -1"<<endl;
}

/*
6
1 3
3 9
2 5
2 5
3 9
2 5
*/


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.rbegin(), x.rend()
#define sz(x) (int) x.size()
#define pb push_back
#define fst first
#define snd second

typedef string st;
typedef long long ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <int,int> ii;
typedef pair <int, ii> iii;

#define MAX 300005

ii p[MAX];

bool comp(ii a,ii b){
    if(a.fst != b.fst)
        return a.fst < b.fst;
    return a.snd > b.snd;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    map<ii,ll> mp;
    ll n,x = -1,y = -1;
    cin >> n;
    for(int i=0;i<n;i++){
        ll a,b;
        cin >> a >> b;
        p[i] = {a,b};
        mp[p[i]] = i+1;
    }
    sort(p,p+n,comp);
    int maxi = 0, index = -1;
    for(int i=0;i<n;i++){
        int x = p[i].fst , y = p[i].snd;
        if(y <= maxi){
            cout << mp[p[i]] << " " << index + 1 << endl;
            return 0;
        }else{
            maxi = y;
            index = mp[p[i]];
        }
    }
    cout << x <<" " << y << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.rbegin(), x.rend()
#define sz(x) (int) x.size()
#define pb push_back
#define fst first
#define snd second

typedef string st;
typedef long long ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <int,int> ii;
typedef pair <int, ii> iii;

#define MAX 300005

ii p[MAX];

bool comp(ii a,ii b){
    if(a.fst != b.fst)
        return a.fst < b.fst;
    return a.snd > b.snd;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    map<ii,int> mp;
    cin >> n;
    for(int i=0;i<n;i++){
        int a,b;
        cin >> a >> b;
        p[i] = {a,b};
        mp[p[i]] = i+1;
    }
    sort(p,p+n,comp);
    int l = 0, r = n-1 , x = -1, j = -1;
    while(l<r){
        if(p[l].fst <= p[r].fst and p[l].snd >= p[r].snd){
            x = mp[p[l]], j = mp[p[r]];
            break;
        }
        l++,r--;
    }
    cout << max(x,j) << " " << min(x,j) << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.rbegin(), x.rend()
#define sz(x) (int) x.size()
#define pb push_back
#define fst first
#define snd second

typedef string st;
typedef long long ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <int,int> ii;
typedef pair <int, ii> iii;

#define MAX 300005

ii p[MAX];

bool comp(ii a,ii b){
    if(a.fst != b.fst)
        return a.fst < b.fst;
    return a.snd > b.snd;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    map<ii,ll> mp;
    ll n,x = -1,y = -1;
    cin >> n;
    for(int i=0;i<n;i++){
        ll a,b;
        cin >> a >> b;
        p[i] = {a,b};
        mp[p[i]] = i+1;
    }
    sort(p,p+n,comp);
    int maxi = 0, index = -1;
    for(int i=0;i<n;i++){
        int x = p[i].fst , y = p[i].snd;
        if(y <= maxi){      //pq o x eu ja sei que é maior igual
            cout << mp[p[i]] << " " << index + 1 << endl;
            return 0;
        }else{
            maxi = y;
            index = mp[p[i]];
        }
    }
    cout << -1 <<" " << -1 << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.rbegin(), x.rend()
#define sz(x) (int) x.size()
#define pb push_back
#define fst first
#define snd second

typedef string st;
typedef long long ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <int,int> ii;
typedef pair <int, ii> iii;

#define MAX 300005

ii p[MAX];

bool comp(ii a,ii b){
    if(a.fst != b.fst)
        return a.fst < b.fst;
    return a.snd > b.snd;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    map<ii,ll> mp;
    ll n,x = -1,y = -1;
    cin >> n;
    for(int i=0;i<n;i++){
        ll a,b;
        cin >> a >> b;
        p[i] = {a,b};
        mp[p[i]] = i+1;
    }
    sort(p,p+n,comp);
    int maxi = 0, index = -1;
    for(int i=0;i<n;i++){
        int x = p[i].fst , y = p[i].snd;
        if(y <= maxi){
            cout << mp[p[i]] << " " << index + 1 << endl;
            return 0;
        }else{
            maxy = y;
            index = mp[p[i]];
        }
    }
    cout << x <<" " << y << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.rbegin(), x.rend()
#define sz(x) (int) x.size()
#define pb push_back
#define fst first
#define snd second

typedef string st;
typedef long long ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <int,int> ii;
typedef pair <int, ii> iii;

#define MAX 300005

ii p[MAX];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    map<ii,ll> mp;
    ll n,x = -1,y = -1;
    cin >> n;
    for(int i=0;i<n;i++){
        ll a,b;
        cin >> a >> b;
        p[i] = {a,b};
        mp[p[i]] = i+1;
    }
    sort(p,p+n);
    for(ll i=1;i<n;i++){
        if(p[i].fst >= p[i-1].fst){
            for(ll j = i-1;j>=0;j--){
                if(p[i].snd <= p[j].snd){
                    x = mp[p[i]], y = mp[p[j]];
                    break;
                }
            }
        }
        if(x!=-1 and y!=-1)break;
    }
    cout << x <<" " << y << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define fst first
#define snd second

typedef string st;
typedef long long ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <int,int> ii;
typedef pair <int, ii> iii;

#define MAX 300005

struct Point{
    int x,y,idx;
    Point(int x1, int y1, int idx1){x = x1;y = y1;idx = idx1;}
    bool operator < (const Point& p){
        if(x != p.x)
            return x < p.x;
        return y > p.y;
    }
};

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, max_y = 0, max_idx = 0;
    cin >> n;
    vector< Point > v;
    for(int i=0;i<n;i++){
        int x,y; cin >> x >> y;
        v.pb(Point(x, y, i));
    }
    sort(all(v));
    for(int i=0;i<n;i++){
        if(v[i].y <= max_y){
            cout << v[i].idx + 1 << " " << max_idx + 1 << endl;
            return 0;
        }else{
            max_y = v[i].y;
            max_idx = v[i].idx;
        }
    }
    cout << -1 << " " << -1 << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.rbegin(), x.rend()
#define sz(x) (int) x.size()
#define pb push_back
#define fst first
#define snd second

typedef string st;
typedef long long ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <int,int> ii;
typedef pair <int, ii> iii;

#define MAX 300005

ii p[MAX];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    map<ii,int> mp;
    int n,x = -1,y = -1;
    cin >> n;
    for(int i=0;i<n;i++){
        int a,b;
        cin >> a >> b;
        p[i] = {a,b};
        mp[p[i]] = i+1;
    }
    sort(p,p+n);
    for(int i=1;i<n;i++){
        if(p[i].fst >= p[i-1].fst){
            for(int j = i-1;j>=0;j--){
                if(p[i].snd <= p[j].snd){
                    x = i+1, y = j+1;
                    break;
                }
            }
            if(x!=-1 and y!=-1)break;
        }
    }
    cout << x <<" " << y << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.rbegin(), x.rend()
#define sz(x) (int) x.size()
#define pb push_back
#define fst first
#define snd second

typedef string st;
typedef long long ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <int,int> ii;
typedef pair <int, ii> iii;

#define MAX 300005

ii p[MAX];

bool comp(ii a,ii b){
    if(a.fst != b.fst)
        return a.fst < b.fst;
    return a.snd > b.snd;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        int a,b;
        cin >> a >> b;
        p[i] = {a,b};
    }
    sort(p,p+n,comp);
    int l = 0, r = n-1 , x = -1, j = -1;
    while(l<r){
        if(p[l].fst <= p[r].fst and p[l].snd >= p[r].snd){
            x = l+1, j = r+1;
            break;
        }
        l++,r--;
    }
    cout << max(x,j) << " " << min(x,j) << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.rbegin(), x.rend()
#define sz(x) (int) x.size()
#define pb push_back
#define fst first
#define snd second

typedef string st;
typedef long long ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <int,int> ii;
typedef pair <int, ii> iii;

#define MAX 300005

ii p[MAX];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    map<ii,int> mp;
    int n,x = -1,y = -1;
    cin >> n;
    for(int i=0;i<n;i++){
        int a,b;
        cin >> a >> b;
        p[i] = {a,b};
        mp[p[i]] = i+1;
    }
    sort(p,p+n);
    for(int i=1;i<n;i++){
        if(p[i].fst >= p[i-1].fst){
            for(int j = i-1;j>=0;j--){
                if(p[i].snd <= p[j].snd){
                    x = mp[p[i]], y = mp[p[j]];
                    break;
                }
            }
            if(x!=-1 and y!=-1)break;
        }
    }
    cout << x <<" " << y << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define fst first
#define snd second

typedef string st;
typedef long long ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <int,int> ii;
typedef pair <int, ii> iii;

#define MAX 300005

struct Point{
    int x,y,idx;
    Point(int x1, int y1, int idx1){x = x1;y = y1;idx = idx1;}
    bool operator < (const Point& p){
        if(x != p.x)
            return x < p.x;
        return y > p.y;
    }
};

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, max_y = 0, max_idx = 0;
    cin >> n;
    vector< Point > v;
    for(int i=0;i<n;i++){
        int x,y; cin >> x >> y;
        v.pb(Point(x, y, i));
    }
    sort(all(v));
    for(int i=0;i<n;i++){
        if(v[i].y <= max_y){
            cout << v[i].idx + 1 << " " << max_idx + 1 << endl;
            return 0;
        }else{
            max_y = v[i].y;
            max_idx = i;
        }
    }
    cout << -1 << " " << -1 << endl;
    return 0;
}


#include<cstdio>
#include<algorithm>
#define $ int
#define inline inline __attribute__((always_inline))
struct S{$ l,r,seat;}s[300003];
$ n,i;
inline $ qr(){
    $ c=getchar(),t=0; for(;c<'0'||'9'<c;)c=getchar();
	for(;'0'<=c&&c<='9';)t=(t<<1)+(t<<3)+c-'0',c=getchar(); return t;
}
bool cmp(S a,S b){return a.l==b.l?a.r>b.r:a.l<b.l;}
int main(){
	for(n=qr();++i<=n;)s[i]=(S){qr(),qr(),i};
	std::sort(s+1,s+n+1,cmp);
	for(i=0;++i<n;)
        if(s[i].r>=s[i+1].r){printf("%d %d",s[i+1].seat,s[i].seat); return 0;}
	puts("-1 -1");
	return 0;
}


/*In The Name of GOD*/
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef long double D;
typedef pair<int,int> pii;

const int N = 1e6+10;

vector <pii> v;

map <pii, int> mrk;

int MAXXl[N+10], MAXXr[N+10];

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

	int n;
	cin >> n;

	for(int i = 0; i < n; i++){
		int x, y;
		cin >> x >> y;
		v.pb(pii(x, y));

		if(mrk[pii(x, y)])
			return cout << mrk[pii(x, y)] << ' ' << i+1 << endl, 0;

		mrk[pii(x, y)] = i+1;
	}

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

	MAXXl[0] = v[0].F,  MAXXr[0] = v[0].S;
	for(int i = 1; i < v.size(); i++){
		if(MAXXr[i-1] >= v[i].S)
			return cout << mrk[pii(v[i].F, v[i].S)] << ' ' << mrk[pii(MAXXl[i-1], MAXXr[i-1])] << endl, 0;

		if(MAXXl[i-1]==v[i].F && v[i].S >= MAXXr[i-1])
			return cout << mrk[pii(MAXXl[i-1], MAXXr[i-1])] << ' ' << mrk[pii(v[i].F, v[i].S)] << endl, 0;

		MAXXr[i] = v[i].S,  MAXXl[i] = v[i].F;
	}

	cout << -1 << ' ' << -1 << endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct p{
	int x,y,index;
}x[300005];
int cmp(p a,p b)
{
	if(a.x!=b.x) return a.x<b.x;
	else return a.y>=b.y;
}
int main()
{
	long long n,m,k;
	scanf("%lld",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&x[i].x,&x[i].y);
		x[i].index=i;
	}
	sort(x,x+n,cmp);
	for(int i=1;i<n;i++)
	{
		if(x[i].y<=x[i-1].y)
		{
			printf("%d %d",x[i].index+1,x[i-1].index+1);
			return 0;
		}
	}
	printf("-1 -1");
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
map <pair < int , int >  , int > mp ;
map < int , int > l ;
int main()
{ ios_base::sync_with_stdio(0);
    cin.tie(0);
     int n ;
     long long a , b ;
     cin >> n ;
     vector < pair < pair < long long , long long > , int >    > vc;
     //vector <pair < int , int > > vc;
     for (int i = 0 ; i< n ; i++)
        cin >> a >> b ,vc.push_back({{b-a,a},i+1});
        sort(vc.rbegin(),vc.rend());
        for (int i = 0 ; i < n ; i++){
                int len = vc[i].first.first;int p = vc[i].first.second;
            int j = i+1;

              {if (vc[j].first.first<=len && p <= vc[j].first.second && p + len >= vc[j].first.first+vc[j].first.second)
                 cout << vc[j].second << " "<<vc[i].second,exit(0);
        }}
        puts("-1 -1");
}


 /*In The Name of GOD*/
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef long double D;
typedef pair<int,int> pii;

const int N = 1e6+10;

vector <pii> vc;

map <pii, int> id;

int mxl[N+10], mxr[N+10];

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

	int n;
	cin >> n;

	for(int i = 0; i < n; i++){
		int x, y;
		cin >> x >> y;
		vc.pb(pii(x, y));

		if(id[pii(x, y)])
			return cout << id[pii(x, y)] << ' ' << i+1, 0;

		id[pii(x, y)] = i+1;
	}

	sort(vc.begin(), vc.end());

	mxl[0] = vc[0].F,  mxr[0] = vc[0].S;
	for(int i = 1; i < vc.size(); i++){
		if(mxr[i-1] >= vc[i].S)
			return cout << id[pii(vc[i].F, vc[i].S)] << ' ' << id[pii(mxl[i-1], mxr[i-1])], 0;

		if(mxl[i-1]==vc[i].F && vc[i].S >= mxr[i-1])
			return cout << id[pii(mxl[i-1], mxr[i-1])] << ' ' << id[pii(vc[i].F, vc[i].S)], 0;

		mxr[i] = vc[i].S,  mxl[i] = vc[i].F;
	}

	cout << -1 << ' ' << -1;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back

int main(){
    ios_base::sync_with_stdio(false);
    //freopen("overcode.in", "r", stdin);
    ll n;
    cin >> n;
    vector < vector<ll> > v;
    for (int i=0;i<n;i++){
        ll x,y;
        cin >> x>> y;
        vector <ll>p;
        p.pb(x);p.pb(-y);p.pb(i);
        v.pb(p);
    }
    sort(v.begin(),v.end());
    ll m = (v[0])[1];
    ll pos=v[0][2];
    for(int i=1;i<n;i++){
        if (v[i][1]>=m){
            cout << v[i][2] +1 << " " << pos+1;
            return 0;
        }else{
            pos=v[i][2];
            m=v[i][1];
        }
    }
	cout << -1 << " " << -1 ;
    return 0;
}


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

signed main() {
	int n,m;
	cin>>n>>m;
	int a[m];
	for(int i=0;i<m;i++) cin>>a[i];
	int sum[m]; sum[m-1] = a[m-1];

	for(int i = m-2; i>=0; i--)
		sum[i] += sum[i+1];

	if(sum[0]<n)
	{
		cout<<-1<<endl;
		return 0;
	}
	int ans[m] = {0};
	for(int i=0;i<m;i++)
	{
		ans[i] = max(i+1, n - sum[i]+1);
	}

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


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

signed main() {
	int n,m;
	cin>>n>>m;
	int a[m];
	for(int i=0;i<m;i++) cin>>a[i];
	int sum[m] = {0}; sum[m-1] = a[m-1];

	for(int i = m-2; i>=0; i--)
		sum[i] = sum[i+1] + a[i];

	int flag = 0;

	if(sum[0]<n)
	{
		flag = 1;
	}

	int ans[m] = {0};
	for(int i=0;i<m;i++)
	{
		ans[i] = max(i+1, n - sum[i]+1);
		if(a[i]+i>n)
		{
			flag = 1;
			break;
		}
	}

	if(flag == 1) cout<<-1<<endl;
	else{
	for(int i=0;i<m;i++) cout<<ans[i]<<' ';
	cout<<endl;
}
}


import java.io.*;
import java.util.*;

public class Main {
	static int H, G;
	static int[] A;

	public static int func(int x) {
		int l = 2 * x;
		int r = 2 * x + 1;
		int ret = A[x];
		if (A[l] == 0 && A[r] == 0) {
			if (x < (1 << G)) {
				ret = -1;
			} else {
				A[x] = 0;
			}
		} else {
			int res = A[l] > A[r] ? func(l) : func(r);
			if (res == -1) {
				ret = -1;
			} else {
				A[x] = res;
			}
		}
		return ret;
	}

	public static void main(String[] args) {
		InputReader in = new InputReader();
		StringBuilder out = new StringBuilder();

		int T = in.nextInt();
		while (T-- > 0) {
			H = in.nextInt();
			G = in.nextInt();
			A = new int[1 << (H + 1)];
			for (int i = 1; i < (1 << H); i++) {
				A[i] = in.nextInt();
			}
			List<Integer> log = new ArrayList<>();
			for (int i = 1; i < (1 << G); i++) {
				while (func(i) != -1) {
					log.add(i);
				}
			}
			long sum = 0;
			for (int i = (1 << G) - 1; i > 0; i--) {
				sum += A[i];
			}
			out.append(sum + "\n");
			for (int x : log) {
				out.append(x + " ");
			}
			out.setCharAt(out.length() - 1, '\n');
		}

		System.out.print(out);
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer st;

		public InputReader() {
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(nextLine());
			}
			return st.nextToken();
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return null;
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Problem_E {
	static int H, G;
	static int[] A;

	public static int func(int x) {
		int l = 2 * x;
		int r = 2 * x + 1;
		int ret = A[x];
		if (A[l] == 0 && A[r] == 0) {
			if (x < (1 << G)) {
				ret = -1;
			} else {
				A[x] = 0;
			}
		} else {
			int res = A[l] > A[r] ? func(l) : func(r);
			if (res == -1) {
				ret = -1;
			} else {
				A[x] = res;
			}
		}
		return ret;
	}

	public static void main(String[] args) {
		InputReader in = new InputReader();
		StringBuilder out = new StringBuilder();

		int T = in.nextInt();
		while (T-- > 0) {
			H = in.nextInt();
			G = in.nextInt();
			A = new int[1 << (H + 1)];
			for (int i = 1; i < (1 << H); i++) {
				A[i] = in.nextInt();
			}
			List<Integer> log = new ArrayList<>();
			for (int i = 1; i < (1 << G); i++) {
				while (func(i) != -1) {
					log.add(i);
				}
			}
			long sum = 0;
			for (int i = (1 << G) - 1; i > 0; i--) {
				sum += A[i];
			}
			out.append(sum).append("\n");
			for (int x : log) {
				out.append(x).append(" ");
			}
			out.setCharAt(out.length() - 1, '\n');
		}

		System.out.print(out);
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer st;

		public InputReader() {
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(nextLine());
			}
			return st.nextToken();
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return null;
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}