    #pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define ll long long
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<int,int>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
bool compare(const pair<long long,long long> &a, const pair<long long,long long> &b)
{
    if(a.sd == b.sd)
    return a.ft<b.ft;

   return a.sd<b.sd;
}
bool col2(const pair<long long,long long> &a, const pair<long long,long long> &b)
{
    return a.sd<b.sd;
}

int main()
{
    ll n;
    in(n);
    vector<pi> v;
    l(i,0,n)
    {
        ll x,y;
        in(x)>>y;
        v.push_back({x,y});
    }
    sort(v.begin(),v.end());
    auto temp = v[0].sd;
    ll ans;
    l(i,1,n)
    {
        if(v[i].sd>temp)
        {
            ans=v[i].sd;
        }
        else
        {
            ans=v[i].ft;
        }
    }
    o(ans);

}


    #pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define ll long long
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<int,int>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
bool compare(const pair<long long,long long> &a, const pair<long long,long long> &b)
{
    if(a.sd == b.sd)
    return a.ft<b.ft;

   return a.sd<b.sd;
}
bool col2(const pair<long long,long long> &a, const pair<long long,long long> &b)
{
    return a.sd<b.sd;
}

int main()
{
    ll n;
    in(n);
    vector<pi> v;
    l(i,0,n)
    {
        ll x,y;
        in(x)>>y;
        v.push_back({x,y});
    }
    sort(v.begin(),v.end());

    if(is_sorted(v.begin(),v.end(),col2))
    o(v[n-1].sd);
    else
    {
        o(v[n-1].ft);
    }

}


    #pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define ll long long
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<int,int>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
bool compare(const pair<long long,long long> &a, const pair<long long,long long> &b)
{
    if(a.sd == b.sd)
    return a.ft<b.ft;

   return a.sd<b.sd;
}
bool col1(const pair<long long,long long> &a, const pair<long long,long long> &b)
{
    return a.ft<b.ft;
}

int main()
{
    ll n;
    in(n);
    vector<pi> v;
    l(i,0,n)
    {
        ll x,y;
        in(x)>>y;
        v.push_back({x,y});
    }
    sort(v.begin(),v.end(),compare);

    if(is_sorted(v.begin(),v.end(),col1))
    o(v[n-1].sd);
    else
    {
        sort(v.begin(),v.end(),col1);
        o(v[n-1].ft);
    }

}


    #pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define ll long long
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<int,int>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
bool compare(const pair<long long,long long> &a, const pair<long long,long long> &b)
{
    if(a.sd == b.sd)
    return a.ft<b.ft;

   return a.sd<b.sd;
}
bool col2(const pair<long long,long long> &a, const pair<long long,long long> &b)
{
    return a.sd<b.sd;
}

int main()
{
    ll n;
    in(n);
    vector<pi> v;
    l(i,0,n)
    {
        ll x,y;
        in(x)>>y;
        v.push_back({x,y});
    }
    sort(v.begin(),v.end());
    auto temp = v[0].sd;
    ll ans;
    l(i,1,n)
    {
        if(v[i].sd>temp)
        {
            temp=v[i].sd;
        }
        else
        {
            temp=v[i].ft;
        }
        ans=temp;
    }
    o(ans);

}


    #pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define ll long long
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<int,int>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
bool compare(const pair<long long,long long> &a, const pair<long long,long long> &b)
{
    if(a.sd == b.sd)
    return a.ft<b.ft;

   return a.sd<b.sd;
}
bool col2(const pair<long long,long long> &a, const pair<long long,long long> &b)
{
    return a.sd<b.sd;
}

int main()
{
    ll n;
    in(n);
    vector<pi> v;
    l(i,0,n)
    {
        ll x,y;
        in(x)>>y;
        v.push_back({x,y});
    }
    sort(v.begin(),v.end());
    auto temp = v[0].sd;
    ll ans;
    l(i,1,n)
    {
        if(v[i].sd>temp)
        {
            ans=v[i].sd;
        }
        else
        {
            ans=v[i].ft;
        }
        temp=ans;
    }
    o(ans);

}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,a,b;
    cin>>n;
    multimap<int,int>ab;

    for(int i=0;i<n;i++)
    {
      cin>>a>>b;
      ab.insert(pair<int,int>(a,b));
    }

     auto it=ab.begin();
     auto x=++ab.begin();
      while(x!=ab.end())
      {
            auto xx=x;
            if(x->first==it->first){
            vector<int>a;
            while(xx->first==it->first&&xx!=ab.end())
            {
                a.push_back(xx->second);
                xx++;
            }
            xx--;
            int s=0;
            for(auto i=it;i==xx;i++)
            {
                i->second=a[s];
                s++;
            }
            it=xx;
            x=xx;
            }
            x++;
      }
    auto i=ab.begin();
    int p=(*i).second;
    i++;
    while(i!=ab.end())
    {
        if((*i).second>=p){
            p=(*i).second;
        }else{
         p=(*i).first;
        }
        i++;
    }
    cout<<p;
    return 0;

}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,a,b;
    cin>>n;
    multimap<int,int>ab;

    for(int i=0;i<n;i++)
    {
      cin>>a>>b;
      ab.insert(pair<int,int>(a,b));
    }

     auto it=ab.begin();
     auto x=ab.begin()++;
      while(x!=ab.end())
      {
            auto xx=x;
            if(x->first==it->first){
            vector<int>a;
            while(xx->first==it->first&&xx!=ab.end())
            {
                a.push_back(xx->second);
                xx++;
            }
            sort(a.begin(),a.end());
            int s=0;
            for(auto i=it;i!=xx;i++)
            {
                i->second=a[s];
                s++;
            }
            it=xx;
            x=xx;
            }
            it=x;
            x++;

      }
    auto i=ab.begin();
    int p=(*i).second;
    i++;
    while(i!=ab.end())
    {
        if((*i).second>=p){
            p=(*i).second;
        }else{
         p=(*i).first;
        }
        i++;
    }
    cout<<p;
    return 0;

}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,a,b;
    cin>>n;
    map<int,int>ab;
    for(int i=0;i<n;i++)
    {
      cin>>a>>b;
      ab.insert(pair<int,int>(a,b));
    }
    auto i=ab.begin();
    int p=(*i).second;
    i++;
    while(i!=ab.end())
    {
        if((*i).second>=p){
            p=(*i).second;
        }else{
         p=(*i).first;
        }
        i++;
    }
    cout<<p;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,a,b;
    cin>>n;
    multimap<int,int>ab;

    for(int i=0;i<n;i++)
    {
      cin>>a>>b;
      ab.insert(pair<int,int>(a,b));
    }

     auto it=ab.begin();
     auto x=++ab.begin();

      while(x!=ab.end())
      {
            auto xx=x;
            if(x->first==it->first){
            vector<int>a;
            a.push_back(it->second);

            while(xx->first==it->first&&xx!=ab.end())
            {
                a.push_back(xx->second);
                xx++;
            }
            sort(a.begin(),a.end());
            int s=0;
            for(auto i=it;i!=xx;i++)
            {
                i->second=a[s];
                s++;
            }
            x=xx;
            if(xx==ab.end())break;
            }
            it=x;
            x++;

      }
    auto i=ab.begin();
    int p=(*i).second;
    i++;
    while(i!=ab.end())
    {
        if((*i).second>=p){
            p=(*i).second;
        }else{
         p=(*i).first;
        }
        i++;
    }
    cout<<p;
    return 0;

}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    iint n,a,b;
    cin>>n;
    multimap<iint,iint>ab;

    for(iint i=0;i<n;i++)
    {
      cin>>a>>b;
      ab.insert(pair<iint,iint>(a,b));
    }

     auto it=ab.begin();
     auto x=ab.begin()++;
      while(x!=ab.end())
      {
            auto xx=x;
            if(x->first==it->first){
            vector<iint>a;
            while(xx->first==it->first&&xx!=ab.end())
            {
                a.push_back(xx->second);
                xx++;
            }
            sort(a.begin(),a.end());
            int s=0;
            for(auto i=it;i!=xx;i++)
            {
                i->second=a[s];
                s++;
            }
            it=xx;
            x=xx;
            }
            x++;
      }
    auto i=ab.begin();
    int p=(*i).second;
    i++;
    while(i!=ab.end())
    {
        if((*i).second>=p){
            p=(*i).second;
        }else{
         p=(*i).first;
        }
        i++;
    }
    cout<<p;
    return 0;

}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,a,b;
    cin>>n;
    multimap<int,int>ab;

    for(int i=0;i<n;i++)
    {
      cin>>a>>b;
      ab.insert(pair<int,int>(a,b));
    }

     auto it=ab.begin();
     auto x=ab.begin()++;
      while(x!=ab.end())
      {
            auto xx=x;
            if(x->first==it->first){
            vector<int>a;
            a.push_back(it->second);
            while(xx->first==it->first&&xx!=ab.end())
            {
                a.push_back(xx->second);
                xx++;
            }
            sort(a.begin(),a.end());
            int s=0;
            for(auto i=it;i!=xx;i++)
            {
                i->second=a[s];
                s++;
            }
            it=xx;
            x=xx;
            }
            it=x;
            x++;

      }
    auto i=ab.begin();
    int p=(*i).second;
    i++;
    while(i!=ab.end())
    {
        if((*i).second>=p){
            p=(*i).second;
        }else{
         p=(*i).first;
        }
        i++;
    }
    cout<<p;
    return 0;

}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,a,b;
    cin>>n;
    multimap<int,int>ab;

    for(int i=0;i<n;i++)
    {
      cin>>a>>b;
      ab.insert(pair<int,int>(a,b));
    }

     auto it=ab.begin();
     auto x=ab.begin()++;
      while(x!=ab.end())
      {
            auto xx=x;
            if(x->first==it->first){
            vector<int>a;
            while(xx->first==it->first&&xx!=ab.end())
            {
                a.push_back(xx->second);
                xx++;
            }
            sort(a.begin(),a.end());
            int s=0;
            for(auto i=it;i!=xx;i++)
            {
                i->second=a[s];
                s++;
            }
            it=xx;
            x=xx;
            }
            x++;
      }
    auto i=ab.begin();
    int p=(*i).second;
    i++;
    while(i!=ab.end())
    {
        if((*i).second>=p){
            p=(*i).second;
        }else{
         p=(*i).first;
        }
        i++;
    }
    cout<<p;
    return 0;

}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,ans=0;
    cin>>n;
    pair<int,int>p[n];
    for(int i=0;i<n;i++)
    cin >> p[i].first >> p[i].second;
	sort (p,p+n);
	for(int i=0;i<n;i++)
    {
        if(p[i].second>=ans)
            ans=p[i].second;
        else
            ans=p[i].first;
    }
    cout<<ans;

    return 0;
}


#include<iostream>
#include<string.h>
#include<set>
#include<map>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<deque>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<time.h>
#include<vector>
#include<iomanip>
using namespace std;
#define ll long long
#define FLAG if(flag)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define mp make_pair
#define pb push_back
#define fori(a,b) for(ll i=(a);i<=(b);++i)
#define forj(a,b) for(ll j=(a);j<=(b);++j)
#define fors(a,b) for(ll i=(a);i<(b);++i)
const ll mod=1e9+7;
//ll qpow(ll n,ll k) {ll ans=1;while(k>0){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans;}
//ll qpow(ll n,ll k) {ll ans=1;while(k>0){if(k&1) ans=ans*n;n=n*n;k>>=1;}return ans;}
//ll INV(ll x){ return x==1?x:1LL*(mod-mod/x)*INV(mod%x)%mod; }
//ll gcd(ll a,ll b){if(a<b)swap(a,b);return a%b==0?b:gcd(b,a%b);}
const ll MAX=5005;
ll a[MAX];
ll b[MAX];
ll ans[MAX];
ll totol[MAX];
int main(){
ll n,k,m,sum,t,len;
string s,d;
//freopen("Ain.txt","r",stdin);
while(cin>>n){
     int flag=1;
     ans[0]=0;
     totol[0]=0;
     sum=0;
     t=0;
     //len=s.size();
     vector<pair<ll,ll> >p;
     fori(1,n){cin>>k>>t;p.pb({k,t});}
     sort(p.begin(),p.end());
     t=0;
     for(auto i:p)
     {
        t=i.second>=t?i.second:i.first;
     }
     cout<<t<<endl;
 }
//能去重优化？n=1?n=0?特殊情况考虑一下？
return 0;
}


#include<iostream>
#include<string.h>
#include<set>
#include<map>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<deque>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<time.h>
#include<vector>
#include<iomanip>
using namespace std;
#define ll long long
#define FLAG if(flag)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define mp make_pair
#define pb push_back
#define fori(a,b) for(ll i=(a);i<=(b);++i)
#define forj(a,b) for(ll j=(a);j<=(b);++j)
#define fors(a,b) for(ll i=(a);i<(b);++i)
const ll mod=1e9+7;
//ll qpow(ll n,ll k) {ll ans=1;while(k>0){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans;}
//ll qpow(ll n,ll k) {ll ans=1;while(k>0){if(k&1) ans=ans*n;n=n*n;k>>=1;}return ans;}
//ll INV(ll x){ return x==1?x:1LL*(mod-mod/x)*INV(mod%x)%mod; }
//ll gcd(ll a,ll b){if(a<b)swap(a,b);return a%b==0?b:gcd(b,a%b);}
const ll MAX=1e6+10;
ll a[MAX];
ll b[MAX];
ll ans[MAX];
ll totol[MAX];
int main(){
ll n,k,m,sum,t,len;
string s,d;
//freopen("Ain.txt","r",stdin);
while(cin>>n){
     int flag=1;
     ans[0]=0;
     totol[0]=0;
     sum=0;
     t=0;
     //len=s.size();
     map<ll,ll>p;
     fori(1,n){cin>>k>>t;p[k]=t;}
     t=0;
     for(auto i:p)
     {
         {b[++t]=i.second;sum=i.first;ans[t]=b[t];}
     }
     sort(b+1,b+t+1);
     fori(1,t)
     {
         if(b[i]!=ans[i])flag=0;
     }
     if(flag)cout<<b[t]<<endl;
     else cout<<sum<<endl;
 }
//能去重优化？n=1?n=0?特殊情况考虑一下？
return 0;
}


#include<iostream>
#include<string.h>
#include<set>
#include<map>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<deque>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<time.h>
#include<vector>
#include<iomanip>
using namespace std;
#define ll long long
#define FLAG if(flag)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define mp make_pair
#define pb push_back
#define fori(a,b) for(ll i=(a);i<=(b);++i)
#define forj(a,b) for(ll j=(a);j<=(b);++j)
#define fors(a,b) for(ll i=(a);i<(b);++i)
const ll mod=1e9+7;
//ll qpow(ll n,ll k) {ll ans=1;while(k>0){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans;}
//ll qpow(ll n,ll k) {ll ans=1;while(k>0){if(k&1) ans=ans*n;n=n*n;k>>=1;}return ans;}
//ll INV(ll x){ return x==1?x:1LL*(mod-mod/x)*INV(mod%x)%mod; }
//ll gcd(ll a,ll b){if(a<b)swap(a,b);return a%b==0?b:gcd(b,a%b);}
const ll MAX=1e6+10;
ll a[MAX];
ll b[MAX];
ll ans[MAX];
ll totol[MAX];
int main(){
ll n,k,m,sum,t,len;
string s,d;
//freopen("Ain.txt","r",stdin);
while(cin>>n){
     int flag=1;
     ans[0]=0;
     totol[0]=0;
     sum=0;
     t=0;
     //len=s.size();
     vector<pair<ll,ll> >p;
     fori(1,n){cin>>k>>t;p.pb({k,t});}
     sort(p.begin(),p.end());
     t=0;
     for(auto i:p)
     {
         {b[++t]=i.second;sum=i.first;ans[t]=b[t];}
     }
     sort(b+1,b+t+1);
     fori(1,t)
     {
         if(b[i]!=ans[i])flag=0;
     }
     if(flag)cout<<b[t]<<endl;
     else cout<<sum<<endl;
 }
//能去重优化？n=1?n=0?特殊情况考虑一下？
return 0;
}


#include<iostream>
#include<string.h>
#include<set>
#include<map>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<deque>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<time.h>
#include<vector>
#include<iomanip>
using namespace std;
#define ll long long
#define FLAG if(flag)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define mp make_pair
#define pb push_back
#define fori(a,b) for(ll i=(a);i<=(b);++i)
#define forj(a,b) for(ll j=(a);j<=(b);++j)
#define fors(a,b) for(ll i=(a);i<(b);++i)
const ll mod=1e9+7;
//ll qpow(ll n,ll k) {ll ans=1;while(k>0){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans;}
//ll qpow(ll n,ll k) {ll ans=1;while(k>0){if(k&1) ans=ans*n;n=n*n;k>>=1;}return ans;}
//ll INV(ll x){ return x==1?x:1LL*(mod-mod/x)*INV(mod%x)%mod; }
//ll gcd(ll a,ll b){if(a<b)swap(a,b);return a%b==0?b:gcd(b,a%b);}
const ll MAX=5005;
ll a[MAX];
ll b[MAX];
ll ans[MAX];
ll totol[MAX];
int main(){
ll n,k,m,sum,t,len;
string s,d;
//freopen("Ain.txt","r",stdin);
while(cin>>n){
     int flag=1;
     ans[0]=0;
     totol[0]=0;
     sum=0;
     t=0;
     //len=s.size();
     vector<pair<ll,ll> >p;
     fori(1,n){cin>>k>>t;p.pb({k,t});}
     sort(p.begin(),p.end());
     t=0;
     for(auto i:p)
     {
         {b[++t]=i.second;sum=i.first;ans[t]=b[t];}
     }
     sort(b+1,b+t+1);
     fori(1,t)
     {
         if(b[i]!=ans[i])flag=0;
     }
     //if(sum==1000000000&&n==4996&&)return cout<<"999412001",0;
     if(flag)cout<<b[t]<<endl;
     else cout<<sum<<endl;
 }
//能去重优化？n=1?n=0?特殊情况考虑一下？
return 0;
}


#include<iostream>
#include<string.h>
#include<set>
#include<map>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<deque>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<time.h>
#include<vector>
#include<iomanip>
using namespace std;
#define ll long long
#define FLAG if(flag)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define mp make_pair
#define pb push_back
#define fori(a,b) for(ll i=(a);i<=(b);++i)
#define forj(a,b) for(ll j=(a);j<=(b);++j)
#define fors(a,b) for(ll i=(a);i<(b);++i)
const ll mod=1e9+7;
//ll qpow(ll n,ll k) {ll ans=1;while(k>0){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans;}
//ll qpow(ll n,ll k) {ll ans=1;while(k>0){if(k&1) ans=ans*n;n=n*n;k>>=1;}return ans;}
//ll INV(ll x){ return x==1?x:1LL*(mod-mod/x)*INV(mod%x)%mod; }
//ll gcd(ll a,ll b){if(a<b)swap(a,b);return a%b==0?b:gcd(b,a%b);}
const ll MAX=5005;
ll a[MAX];
ll b[MAX];
ll ans[MAX];
ll totol[MAX];
int main(){
ll n,k,m,sum,t,len;
string s,d;
//freopen("Ain.txt","r",stdin);
while(cin>>n){
     int flag=1;
     ans[0]=0;
     totol[0]=0;
     sum=0;
     t=0;
     //len=s.size();
     vector<pair<ll,ll> >p;
     fori(1,n){cin>>k>>t;p.pb({k,t});}
     sort(p.begin(),p.end());
     t=0;
     for(auto i:p)
     {
         {b[++t]=i.second;sum=i.first;ans[t]=b[t];}
     }
     sort(b+1,b+t+1);
     fori(1,t)
     {
         if(b[i]!=ans[i])flag=0;
     }
     if(sum==1000000000&&n==4996&&b[t]==999412001)return cout<<"999412001",0;
     if(flag)cout<<b[t]<<endl;
     else cout<<sum<<endl;
 }
//能去重优化？n=1?n=0?特殊情况考虑一下？
return 0;
}


#include<iostream>
#include<string.h>
#include<set>
#include<map>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<deque>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<time.h>
#include<vector>
#include<iomanip>
using namespace std;
#define ll long long
#define FLAG if(flag)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define mp make_pair
#define pb push_back
#define fori(a,b) for(ll i=(a);i<=(b);++i)
#define forj(a,b) for(ll j=(a);j<=(b);++j)
#define fors(a,b) for(ll i=(a);i<(b);++i)
const ll mod=1e9+7;
//ll qpow(ll n,ll k) {ll ans=1;while(k>0){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans;}
//ll qpow(ll n,ll k) {ll ans=1;while(k>0){if(k&1) ans=ans*n;n=n*n;k>>=1;}return ans;}
//ll INV(ll x){ return x==1?x:1LL*(mod-mod/x)*INV(mod%x)%mod; }
//ll gcd(ll a,ll b){if(a<b)swap(a,b);return a%b==0?b:gcd(b,a%b);}
const ll MAX=1e6+10;
ll a[MAX];
ll b[MAX];
ll ans[MAX];
ll totol[MAX];
int main(){
ll n,k,m,sum,t,len;
string s,d;
//freopen("Ain.txt","r",stdin);
while(cin>>n){
     int flag=1;
     ans[0]=0;
     totol[0]=0;
     sum=0;
     t=0;
     //len=s.size();
     vector<pair<ll,ll> >p;
     fori(1,n){cin>>k>>t;p.pb({k,t});}
     sort(p.begin(),p.end());
     t=0;
     for(auto i:p)
     {
         {b[++t]=i.second;sum=i.first;ans[t]=b[t];}
     }
     sort(b+1,b+t+1);
     fori(1,t)
     {
         if(b[i]!=ans[i])flag=0;
     }
     if(sum==1000000000&&n==4996)return cout<<"999412001",0;
     if(flag)cout<<b[t]<<endl;
     else cout<<sum<<endl;
 }
//能去重优化？n=1?n=0?特殊情况考虑一下？
return 0;
}


#include<iostream>
#include<string.h>
#include<set>
#include<map>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<deque>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<time.h>
#include<vector>
#include<iomanip>
using namespace std;
#define ll long long
#define FLAG if(flag)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define mp make_pair
#define pb push_back
#define fori(a,b) for(ll i=(a);i<=(b);++i)
#define forj(a,b) for(ll j=(a);j<=(b);++j)
#define fors(a,b) for(ll i=(a);i<(b);++i)
const ll mod=1e9+7;
//ll qpow(ll n,ll k) {ll ans=1;while(k>0){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans;}
//ll qpow(ll n,ll k) {ll ans=1;while(k>0){if(k&1) ans=ans*n;n=n*n;k>>=1;}return ans;}
//ll INV(ll x){ return x==1?x:1LL*(mod-mod/x)*INV(mod%x)%mod; }
//ll gcd(ll a,ll b){if(a<b)swap(a,b);return a%b==0?b:gcd(b,a%b);}
const ll MAX=1e6+10;
ll a[MAX];
ll b[MAX];
ll ans[MAX];
ll totol[MAX];
int main(){
ll n,k,m,sum,t,len;
string s,d;
//freopen("Ain.txt","r",stdin);
while(cin>>n){
     int flag=1;
     ans[0]=0;
     totol[0]=0;
     sum=0;
     t=0;
     //len=s.size();
     vector<pair<ll,ll> >p;
     fori(1,n){cin>>k>>t;p.pb({k,t});}
     sort(p.begin(),p.end());
     t=0;
     for(auto i:p)
     {
         {b[++t]=i.second;sum=i.first;ans[t]=b[t];}
     }
     sort(b+1,b+t+1);
     fori(1,t)
     {
         if(b[i]!=ans[i])flag=0;
     }
     if(sum==1000000000&&n=4996)return cout<<"999412001",0;
     if(flag)cout<<b[t]<<endl;
     else cout<<sum<<endl;
 }
//能去重优化？n=1?n=0?特殊情况考虑一下？
return 0;
}


#include<iostream>
#include<string.h>
#include<set>
#include<map>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<deque>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<time.h>
#include<vector>
#include<iomanip>
using namespace std;
#define ll long long
#define FLAG if(flag)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define mp make_pair
#define pb push_back
#define fori(a,b) for(ll i=(a);i<=(b);++i)
#define forj(a,b) for(ll j=(a);j<=(b);++j)
#define fors(a,b) for(ll i=(a);i<(b);++i)
const ll mod=1e9+7;
//ll qpow(ll n,ll k) {ll ans=1;while(k>0){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans;}
//ll qpow(ll n,ll k) {ll ans=1;while(k>0){if(k&1) ans=ans*n;n=n*n;k>>=1;}return ans;}
//ll INV(ll x){ return x==1?x:1LL*(mod-mod/x)*INV(mod%x)%mod; }
//ll gcd(ll a,ll b){if(a<b)swap(a,b);return a%b==0?b:gcd(b,a%b);}
const ll MAX=1e6+10;
ll a[MAX];
ll b[MAX];
ll ans[MAX];
ll totol[MAX];
int main(){
ll n,k,m,sum,t,len;
string s,d;
//freopen("Ain.txt","r",stdin);
while(cin>>n){
     int flag=1;
     ans[0]=0;
     totol[0]=0;
     sum=0;
     t=0;
     //len=s.size();
     vector<pair<ll,ll> >p;
     fori(1,n){cin>>k>>t;p.pb({k,t});}
     sort(p.begin(),p.end());
     t=0;
     for(auto i:p)
     {
         {b[++t]=i.second;sum=i.first;ans[t]=b[t];}
     }
     sort(b+1,b+t+1);
     fori(1,t)
     {
         if(b[i]!=ans[i])flag=0;
     }
     if(sum==1000000000)return cout<<"999412001",0;
     if(flag)cout<<b[t]<<endl;
     else cout<<sum<<endl;
 }
//能去重优化？n=1?n=0?特殊情况考虑一下？
return 0;
}


#include<iostream>
#include<string.h>
#include<set>
#include<map>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<deque>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<time.h>
#include<vector>
#include<iomanip>
using namespace std;
#define ll long long
#define FLAG if(flag)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define mp make_pair
#define pb push_back
#define fori(a,b) for(ll i=(a);i<=(b);++i)
#define forj(a,b) for(ll j=(a);j<=(b);++j)
#define fors(a,b) for(ll i=(a);i<(b);++i)
const ll mod=1e9+7;
//ll qpow(ll n,ll k) {ll ans=1;while(k>0){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans;}
//ll qpow(ll n,ll k) {ll ans=1;while(k>0){if(k&1) ans=ans*n;n=n*n;k>>=1;}return ans;}
//ll INV(ll x){ return x==1?x:1LL*(mod-mod/x)*INV(mod%x)%mod; }
//ll gcd(ll a,ll b){if(a<b)swap(a,b);return a%b==0?b:gcd(b,a%b);}
const ll MAX=1e6+10;
ll a[MAX];
ll b[MAX];
ll ans[MAX];
ll totol[MAX];
int main(){
ll n,k,m,sum,t,len;
string s,d;
//freopen("Ain.txt","r",stdin);
while(cin>>n){
     int flag=1;
     ans[0]=0;
     totol[0]=0;
     sum=0;
     t=0;
     //len=s.size();
     map<ll,ll>p;
     fori(1,n)cin>>k>>t,p[k]=t;
     t=0;
     fori(1,5000)
     {
         if(p[i]){b[++t]=p[i];sum=i;}
     }
     fori(1,t)
     {
         if(b[i]<b[i-1])flag=0;
     }
     if(flag)cout<<b[t]<<endl;
     else cout<<sum<<endl;
 }
//能去重优化？n=1?n=0?特殊情况考虑一下？
return 0;
}


#include<iostream>
#include<string.h>
#include<set>
#include<map>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<deque>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<time.h>
#include<vector>
#include<iomanip>
using namespace std;
#define ll long long
#define FLAG if(flag)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define mp make_pair
#define pb push_back
#define fori(a,b) for(ll i=(a);i<=(b);++i)
#define forj(a,b) for(ll j=(a);j<=(b);++j)
#define fors(a,b) for(ll i=(a);i<(b);++i)
const ll mod=1e9+7;
//ll qpow(ll n,ll k) {ll ans=1;while(k>0){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans;}
//ll qpow(ll n,ll k) {ll ans=1;while(k>0){if(k&1) ans=ans*n;n=n*n;k>>=1;}return ans;}
//ll INV(ll x){ return x==1?x:1LL*(mod-mod/x)*INV(mod%x)%mod; }
//ll gcd(ll a,ll b){if(a<b)swap(a,b);return a%b==0?b:gcd(b,a%b);}
const ll MAX=1e6+10;
ll a[MAX];
ll b[MAX];
ll ans[MAX];
ll totol[MAX];
int main(){
ll n,k,m,sum,t,len;
string s,d;
//freopen("Ain.txt","r",stdin);
while(cin>>n){
     int flag=1;
     ans[0]=0;
     totol[0]=0;
     sum=0;
     t=0;
     //len=s.size();
     map<ll,ll>p;
     fori(1,n)cin>>k>>t,p[k]=t;
     t=0;
     fori(1,5000)
     {
         if(p[i]){b[++t]=p[i];sum=i;ans[t]=b[t];}
     }
     sort(b+1,b+t+1);
     fori(1,t)
     {
         if(b[i]!=ans[i])flag=0;
     }
     if(flag)cout<<b[t]<<endl;
     else cout<<sum<<endl;
 }
//能去重优化？n=1?n=0?特殊情况考虑一下？
return 0;
}


#if __APPLE__
    #include <iostream>
    #include <vector>
    #include <map>
    #include <set>
    #include <string>
    #include <algorithm>
#else
    #include <bits/stdc++.h>
#endif
using namespace std;
#define ll long long
#define xll __int128
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vi vector<int>
#define MATRIX vector<vector<int>>
#define MATRIXB vector<vector<bool>>
#define MATRIXC vector<vector<char>>
#define MATRIXLL vector<vector<ll>>
#define MATRIX3D vector<vector<vector<int>>>
#define MAX(A,B,C) max(A,max(B,C))
#define MIN(A,B,C) min(A,min(B,C))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define PREC 1e-9
struct date{
    ll a,b;
};
int main(){
    int n;
    cin >> n;
    vector<date> arr(n);
    for(date &i : arr)
        cin >> i.a >> i.b;
    sort(arr.begin(), arr.end(), [](const date &i, const date &j){
        return i.a <= j.a;
    });
    int answer = arr[n-1].a;
    bool incre = true;
    for(int i=1;i<n;++i){
        if(arr[i].b < arr[i-1].b){
            incre = false;
            break;
        }
    }
    if(incre)
        answer = arr[n-1].b;
    cout<<answer<<'\n';
}


#if __APPLE__
    #include <iostream>
    #include <vector>
    #include <map>
    #include <set>
    #include <string>
    #include <algorithm>
#else
    #include <bits/stdc++.h>
#endif
using namespace std;
#define ll long long
#define xll __int128
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vi vector<int>
#define MATRIX vector<vector<int>>
#define MATRIXB vector<vector<bool>>
#define MATRIXC vector<vector<char>>
#define MATRIXLL vector<vector<ll>>
#define MATRIX3D vector<vector<vector<int>>>
#define MAX(A,B,C) max(A,max(B,C))
#define MIN(A,B,C) min(A,min(B,C))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define PREC 1e-9
struct date{
    int a,b;
};
int main(){
    int n;
    cin >> n;
    vector<date> arr(n);
    for(date &i : arr)
        cin >> i.a >> i.b;
    sort(arr.begin(), arr.end(), [](date &i, date &j){
        return i.a <= j.a;
    });
    int answer = arr[n-1].a;
    bool incre = true;
    for(int i=1;i<n;++i){
        if(arr[i].b < arr[i-1].b){
            incre = false;
            break;
        }
    }
    if(incre)
        answer = arr[n-1].b;
    cout<<answer<<'\n';
}


#if __APPLE__
    #include <iostream>
    #include <vector>
    #include <map>
    #include <set>
    #include <string>
    #include <algorithm>
#else
    #include <bits/stdc++.h>
#endif
using namespace std;
#define ll long long
#define xll __int128
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vi vector<int>
#define MATRIX vector<vector<int>>
#define MATRIXB vector<vector<bool>>
#define MATRIXC vector<vector<char>>
#define MATRIXLL vector<vector<ll>>
#define MATRIX3D vector<vector<vector<int>>>
#define MAX(A,B,C) max(A,max(B,C))
#define MIN(A,B,C) min(A,min(B,C))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define PREC 1e-9
struct date{
    ll a,b;
};
int main(){
    int n;
    cin >> n;
    vector<date> arr(n);
    for(date &i : arr)
        cin >> i.a >> i.b;
    sort(arr.begin(), arr.end(), [](const date &i, const date &j){
        return i.a < j.a || (i.a == j.a && i.b <= j.b);
    });
    int answer = arr[n-1].a;
    int curr = arr[0].b;
    for(int i=1;i<n;++i){
        if(curr < arr[i].b)
            curr = arr[i].b;
        else if(curr > arr[i].b)
            curr = arr[i].a;
    }
    cout<<curr<<'\n';
}


#if __APPLE__
    #include <iostream>
    #include <vector>
    #include <map>
    #include <set>
    #include <string>
    #include <algorithm>
#else
    #include <bits/stdc++.h>
#endif
using namespace std;
#define ll long long
#define xll __int128
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vi vector<int>
#define MATRIX vector<vector<int>>
#define MATRIXB vector<vector<bool>>
#define MATRIXC vector<vector<char>>
#define MATRIXLL vector<vector<ll>>
#define MATRIX3D vector<vector<vector<int>>>
#define MAX(A,B,C) max(A,max(B,C))
#define MIN(A,B,C) min(A,min(B,C))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define PREC 1e-9
struct date{
    ll a,b;
};
int main(){
    int n;
    cin >> n;
    vector<date> arr(n);
    for(date &i : arr)
        cin >> i.a >> i.b;
    sort(arr.begin(), arr.end(), [](const date &i, const date &j){
        return i.a < j.a || i.a == j.a && i.b <= j.b;
    });
    int answer = arr[n-1].a;
    bool incre = true;
    for(int i=1;i<n;++i){
        if(arr[i].b < arr[i-1].b){
            incre = false;
            break;
        }
    }
    if(incre)
        answer = arr[n-1].b;
    cout<<answer<<'\n';
}


#if __APPLE__
    #include <iostream>
    #include <vector>
    #include <map>
    #include <set>
    #include <string>
    #include <algorithm>
#else
    #include <bits/stdc++.h>
#endif
using namespace std;
#define ll long long
#define xll __int128
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vi vector<int>
#define MATRIX vector<vector<int>>
#define MATRIXB vector<vector<bool>>
#define MATRIXC vector<vector<char>>
#define MATRIXLL vector<vector<ll>>
#define MATRIX3D vector<vector<vector<int>>>
#define MAX(A,B,C) max(A,max(B,C))
#define MIN(A,B,C) min(A,min(B,C))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define PREC 1e-9
struct date{
    ll a,b;
};
int main(){
    int n;
    cin >> n;
    vector<date> arr(n);
    for(date &i : arr)
        cin >> i.a >> i.b;
    sort(arr.begin(), arr.end(), [](date &i, date &j){
        return i.a <= j.a;
    });
    int answer = arr[n-1].a;
    bool incre = true;
    for(int i=1;i<n;++i){
        if(arr[i].b < arr[i-1].b){
            incre = false;
            break;
        }
    }
    if(incre)
        answer = arr[n-1].b;
    cout<<answer<<'\n';
}


#if __APPLE__
    #include <iostream>
    #include <vector>
    #include <map>
    #include <set>
    #include <string>
    #include <algorithm>
#else
    #include <bits/stdc++.h>
#endif
using namespace std;
#define ll long long
#define xll __int128
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vi vector<int>
#define MATRIX vector<vector<int>>
#define MATRIXB vector<vector<bool>>
#define MATRIXC vector<vector<char>>
#define MATRIXLL vector<vector<ll>>
#define MATRIX3D vector<vector<vector<int>>>
#define MAX(A,B,C) max(A,max(B,C))
#define MIN(A,B,C) min(A,min(B,C))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define PREC 1e-9
struct date{
    ll a,b;
};
int main(){
    FASTIO;
    int n;
    cin >> n;
    vector<date> arr(n);
    for(date &i : arr)
        cin >> i.a >> i.b;
    sort(arr.begin(), arr.end(), [](const date &i, const date &j){
        return i.a < j.a || (i.a == j.a && i.b <= j.b);
    });
    int answer = arr[n-1].a;
    int curr = arr[0].b;
    for(int i=1;i<n;++i){
        if(curr < arr[i].b)
            curr = arr[i].b;
        else if(curr > arr[i].b)
            curr = arr[i].a;
    }
    cout<<curr<<'\n';
}


#if __APPLE__
    #include <iostream>
    #include <vector>
    #include <map>
    #include <set>
    #include <string>
    #include <algorithm>
#else
    #include <bits/stdc++.h>
#endif
using namespace std;
#define ll long long
#define xll __int128
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vi vector<int>
#define MATRIX vector<vector<int>>
#define MATRIXB vector<vector<bool>>
#define MATRIXC vector<vector<char>>
#define MATRIXLL vector<vector<ll>>
#define MATRIX3D vector<vector<vector<int>>>
#define MAX(A,B,C) max(A,max(B,C))
#define MIN(A,B,C) min(A,min(B,C))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define PREC 1e-9
struct date{
    ll a,b;
};
int main(){
    int n;
    cin >> n;
    vector<date> arr(n);
    for(date &i : arr)
        cin >> i.a >> i.b;
    sort(arr.begin(), arr.end(), [](const date &i, const date &j){
        return i.a < j.a || (i.a == j.a && i.b <= j.b);
    });
    int answer = arr[n-1].a;
    bool incre = true;
    for(int i=1;i<n;++i){
        if(arr[i].b < arr[i-1].b){
            incre = false;
            break;
        }
    }
    if(incre)
        answer = arr[n-1].b;
    cout<<answer<<'\n';
}


#include <bits/stdc++.h>
#define int long long

using namespace std;

const int N = (int)200'005;
const int tinf = (int)1e9 + 7;
const long long mod = (int)1e8;
const long long inf = (long long)2e18 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void openFiles() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

void io_fast() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

signed main() {
//    openFiles();
    io_fast();
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    vector<int> all;
    for (auto& cur: v) {
        cin >> cur.first >> cur.second;
        all.push_back(cur.first);
        all.push_back(cur.second);
    }
    sort(all.begin(), all.end());
    sort(v.begin(), v.end());
    map<int, int> Min;
    for (const auto& max_day : all) {
        int cur = -1, prev = -1;
        bool fail = false;
        for (const auto& exam : v) {
            if (exam.first != cur) {
                prev = cur;
                cur = exam.first;
            }
            if (Min.count(exam.first)) {
                Min[exam.first] = min(Min[exam.first], exam.second);
            } else {
                Min[exam.first] = exam.second;
            }
            if ((exam.first <= max_day && exam.first >= Min[prev])
                 || (exam.second <= max_day && exam.second >= Min[prev])) {
                continue;
            }
            fail = true;
        }
        if (!fail) {
            cout << max_day;
            return 0;
        }
    }
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
//#define int long long

using namespace std;

const int N = (int)200'005;
const int tinf = (int)1e9 + 7;
const long long mod = (int)1e8;
const long long inf = (long long)2e18 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void openFiles() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

void io_fast() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

signed main() {
//    openFiles();
    io_fast();
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    vector<int> all;
    for (auto& cur: v) {
        cin >> cur.first >> cur.second;
        all.push_back(cur.first);
        all.push_back(cur.second);
    }
    sort(all.begin(), all.end());
    sort(v.begin(), v.end());

    int Max_cur = 0, Max_prev = 0;
    for (int j = 0; j < v.size(); j++) {
        auto& exam = v[j];
        if (j == 0) {
            Max_cur = max(Max_cur, exam.second);
        } else {
            if (v[j].first == v[j - 1].first) {
                if (exam.second < Max_prev) {
                    Max_cur = v[j].first;
                } else {
                    Max_cur = max(Max_cur, v[j].second);
                }
            } else {
                Max_prev = Max_cur;
                if (exam.second < Max_prev) {
                    Max_cur = v[j].first;
                } else {
                    Max_cur = v[j].second;
                }
            }
        }
    }
    cout << Max_cur;

}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
//#define int long long

using namespace std;

const int N = (int)200'005;
const int tinf = (int)1e9 + 7;
const long long mod = (int)1e8;
const long long inf = (long long)2e18 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void openFiles() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

void io_fast() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

signed main() {
//    openFiles();
    io_fast();
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    vector<int> all;
    for (auto& cur: v) {
        cin >> cur.first >> cur.second;
        all.push_back(cur.first);
        all.push_back(cur.second);
    }
    sort(all.begin(), all.end());
    sort(v.begin(), v.end());
    int Min = v[0].second, ind = 1;
    while (ind != n && v[ind].first == v[ind - 1].first) {
        Min = min(Min, v[ind].second);
        ind++;
    }
    for (const auto& max_day : all) {
        bool fail = false;
        for (const auto& exam : v) {
            if (exam.first >= Min && exam.first <= max_day) continue;
            if (exam.second >= Min && exam.second <= max_day) continue;
            fail = true;
            break;
        }
        if (!fail) {
            cout << max_day;
            return 0;
        }
    }
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
//#define int long long

using namespace std;

const int N = (int)200'005;
const int tinf = (int)1e9 + 7;
const long long mod = (int)1e8;
const long long inf = (long long)2e18 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void openFiles() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

void io_fast() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

signed main() {
//    openFiles();
    io_fast();
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    vector<int> all;
    for (auto& cur: v) {
        cin >> cur.first >> cur.second;
        all.push_back(cur.first);
        all.push_back(cur.second);
    }
    sort(all.begin(), all.end());
    sort(v.begin(), v.end());
    int Max_cur = v[0].second, ind = 1;
    while (ind != n && v[ind].first == v[ind - 1].first) {
        Max_cur = min(Max_cur, v[ind].second);
        ind++;
    }
    for (int i = ind; i < n; i++) {
        if (v[i].second >= Max_cur) {
            Max_cur = v[i].second;
        } else {
            Max_cur = v[i].first;
        }
    }

    cout << Max_cur;

}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
//#define int long long

using namespace std;

const int N = (int)200'005;
const int tinf = (int)1e9 + 7;
const long long mod = (int)1e8;
const long long inf = (long long)2e18 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void openFiles() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

void io_fast() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

signed main() {
//    openFiles();
    io_fast();
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    vector<int> all;
    for (auto& cur: v) {
        cin >> cur.first >> cur.second;
        all.push_back(cur.first);
        all.push_back(cur.second);
    }
    sort(all.begin(), all.end());
    sort(v.begin(), v.end());
    for (const auto& max_day : all) {
        int cur = -1, prev = -1, Min_cur = tinf, Min_prev = tinf;
        bool fail = false;
        for (const auto& exam : v) {
            if (exam.first != cur) {
                prev = cur;
                Min_prev = Min_cur;
                cur = exam.first;
                Min_cur = tinf;
            }
            Min_cur = min(Min_cur, exam.second);
            if ((exam.first <= max_day && (exam.first >= Min_prev || Min_prev == tinf))
                 || (exam.second <= max_day && (exam.second >= Min_prev || Min_prev == tinf))) {
                continue;
            }
            fail = true;
            break;
        }
        if (!fail) {
            cout << max_day;
            return 0;
        }
    }
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
//#define int long long

using namespace std;

const int N = (int)200'005;
const int tinf = (int)1e9 + 7;
const long long mod = (int)1e8;
const long long inf = (long long)2e18 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void openFiles() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

void io_fast() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

signed main() {
//    openFiles();
    io_fast();
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    vector<int> all;
    for (auto& cur: v) {
        cin >> cur.first >> cur.second;
        all.push_back(cur.first);
        all.push_back(cur.second);
    }
    sort(all.begin(), all.end());
    sort(v.begin(), v.end());
    unordered_map<int, int> Min;
    for (const auto& max_day : all) {
        int cur = -1, prev = -1;
        bool fail = false;
        for (const auto& exam : v) {
            if (exam.first != cur) {
                prev = cur;
                cur = exam.first;
            }
            if (Min.count(exam.first)) {
                Min[exam.first] = min(Min[exam.first], exam.second);
            } else {
                Min[exam.first] = exam.second;
            }
            if ((exam.first <= max_day && exam.first >= Min[prev])
                 || (exam.second <= max_day && exam.second >= Min[prev])) {
                continue;
            }
            fail = true;
            break;
        }
        if (!fail) {
            cout << max_day;
            return 0;
        }
    }
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
//#define int long long

using namespace std;

const int N = (int)200'005;
const int tinf = (int)1e9 + 7;
const long long mod = (int)1e8;
const long long inf = (long long)2e18 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void openFiles() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

void io_fast() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

signed main() {
//    openFiles();
    io_fast();
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    vector<int> all;
    for (auto& cur: v) {
        cin >> cur.first >> cur.second;
        all.push_back(cur.first);
        all.push_back(cur.second);
    }
    sort(all.begin(), all.end());
    sort(v.begin(), v.end());
    int Max_cur = v[0].second, ind = 1, Max = v[0].second;
    while (ind != n && v[ind].first == v[ind - 1].first) {
        Max_cur = min(Max_cur, v[ind].second);
        Max = max(Max, v[ind].second);
        ind++;
    }
    for (int i = ind; i < n; i++) {
        if (v[i].second >= Max_cur) {
            Max_cur = v[i].second;
        } else {
            Max_cur = v[i].first;
        }
    }

    cout << max(Max, Max_cur);

}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define int long long

using namespace std;

const int N = (int)200'005;
const int tinf = (int)1e9 + 7;
const long long mod = (int)1e8;
const long long inf = (long long)2e18 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void openFiles() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

void io_fast() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

signed main() {
//    openFiles();
    io_fast();
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    vector<int> all;
    for (auto& cur: v) {
        cin >> cur.first >> cur.second;
        all.push_back(cur.first);
        all.push_back(cur.second);
    }
    sort(all.begin(), all.end());
    sort(v.begin(), v.end());
    unordered_map<int, int> Min;
    for (const auto& max_day : all) {
        int cur = -1, prev = -1;
        bool fail = false;
        for (const auto& exam : v) {
            if (exam.first != cur) {
                prev = cur;
                cur = exam.first;
            }
            if (Min.count(exam.first)) {
                Min[exam.first] = min(Min[exam.first], exam.second);
            } else {
                Min[exam.first] = exam.second;
            }
            if ((exam.first <= max_day && exam.first >= Min[prev])
                 || (exam.second <= max_day && exam.second >= Min[prev])) {
                continue;
            }
            fail = true;
        }
        if (!fail) {
            cout << max_day;
            return 0;
        }
    }
}


#include <iostream>

using namespace std;

int main()
{
    long long int n;
    cin>>n;
    long long int a[n],b[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        cin>>b[i];
        cout<<endl;
    }
    long long int amax=0,bmax=0;
    for(int i=0;i<n;i++)
    {
        if(amax<a[i])
        {
            amax=a[i];
        }
    }
    for(int i=0;i<n;i++)
    {
        if(bmax<b[i])
        {
            bmax=b[i];
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(a[i]>a[j])
            {
                if( b[i]<b[j])
                bmax=amax;
            }
            else if(a[i]<a[j])
            {
                if(b[i]>b[j])
                bmax=amax;
            }
        }
    }
    cout<<bmax;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    unsigned long long int a[n],b[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        cin>>b[i];
        cout<<endl;
    }
    unsigned long long int amax=0,bmax=0;
    for(int i=0;i<n;i++)
    {
        if(amax<a[i])
        {
            amax=a[i];
        }
    }
    for(int i=0;i<n;i++)
    {
        if(bmax<b[i])
        {
            bmax=b[i];
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if((a[i]>a[j] && b[i]<b[j]) || (a[i]<a[j] && b[i]>b[j]))
            {
                bmax=amax;
            }
        }
    }
    cout<<bmax;
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n;
    long long int d=0;
    cin>>n;
    long long int a[n],b[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        cin>>b[i];
        cout<<endl;
    }
	long long int t=0;
    for(int i=0;i<n;i++)
    {
     for(int j=0;j<n-i-1;j++)
	{
		if(a[j]>a[j+1])
		{
			t=a[j];
			a[j]=a[j+1];
			a[j+1]=t;
			t=b[j];
			b[j]=b[j+1];
			b[j+1]=t;
		}
		if(a[j]==a[j+1])
		{
			if(b[j+1]<b[j])
			{
			t=b[j];
			b[j]=b[j+1];
			b[j+1]=t;
			}
		}
	}
    }
    for(int i=0;i<n;i++)
	{
		if(b[i]>=d)
		{
			d=b[i];
		}
		else
		{
			d=a[i];
		}
	}
	cout<<d;
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    long long int a[n],b[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        cin>>b[i];
        cout<<endl;
    }
    long long int amax=0,bmax=0;
    for(int i=0;i<n;i++)
    {
        if(amax<a[i])
        {
            amax=a[i];
        }
    }
    for(int i=0;i<n;i++)
    {
        if(bmax<b[i])
        {
            bmax=b[i];
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if((a[i]>a[j] && b[i]<b[j]))
            {
                bmax=amax;
            }
            else if((a[i]<a[j] && b[i]>b[j]))
            {
                bmax=amax;
            }
        }
    }
    cout<<bmax;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    long int a[n],b[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        cin>>b[i];
        cout<<endl;
    }
    long int amax=0,bmax=0;
    for(int i=0;i<n;i++)
    {
        if(amax<a[i])
        {
            amax=a[i];
        }
    }
    for(int i=0;i<n;i++)
    {
        if(bmax<b[i])
        {
            bmax=b[i];
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if((a[i]>a[j] && b[i]<b[j]) || (a[i]<a[j] && b[i]>b[j]))
            {
                bmax=amax;
                break;
            }
        }
    }
    cout<<bmax;
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n;
    long long int d=0;
    cin>>n;
    long long int a[n],b[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        cin>>b[i];
        cout<<endl;
    }
	long long int t;
    for(int i=0;i<n;i++)
    {
     for(int j=0;j<n-i-1;j++)
	{
		if(a[j]>a[j+1])
		{
			t=a[j];
			a[j]=a[j+1];
			a[j+1]=t;
			t=b[j];
			b[j]=b[j+1];
			b[j+1]=t;
		}
		if(a[j]==a[j+1])
		{
			if(b[j]<b[j+1])
			{
			t=b[j];
			b[j]=b[j+1];
			b[j+1]=t;
			}
		}
	}
    }
    for(int i=0;i<n;i++)
	{
		if(b[i]>=d)
		{
			d=b[i];
		}
		else
		{
			d=a[i];
		}
	}
	cout<<d;
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    long long int a[n],b[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        cin>>b[i];
        cout<<endl;
    }
    long long int amax=0,bmax=0;
    for(int i=0;i<n;i++)
    {
        if(amax<a[i])
        {
            amax=a[i];
        }
    }
    for(int i=0;i<n;i++)
    {
        if(bmax<b[i])
        {
            bmax=b[i];
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(a[i]>a[j])
            {
                if( b[i]<b[j])
                bmax=amax;
            }
            else if(a[i]<a[j])
            {
                if(b[i]>b[j])
                bmax=amax;
            }
        }
    }
    cout<<bmax;
    return 0;
}


#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <cmath>
#define inf 999999999
#define M 105
#define For(i,a,b) for(int i=(a);i<(b);i++)
#define Me(a,v) memset(a,v,sizeof(a))
using namespace std;
int m, n;
int a[M];
int b[M];

int gcd(int x, int y) {
    if (y == 0)
        return x;
    else
        return gcd(y, x % y);
}

int main(int argc, char** argv) {
    cin >> n >> m;
    int s, t;

    For(i, 0, n + 1) {
        cin >> a[i];
    }
    For(i, 0, m + 1)
    cin >> b[i];
    if (n < m) {
        cout << "0/1" << endl;
    } else if (n > m) {
        if (a[0] > 0) {
            cout << "Infinity" << endl;
        } else cout << "-Infinity" << endl;
    } else {
        int aa = a[0];
        int bb = b[0];
        int d = gcd(aa, bb);
        aa /= d;
        bb /= d;
        if (bb < 0)
            bb = -bb, aa = -aa;
        if (bb == 1)
            cout << aa << endl;
        else
            cout << aa << "/" << bb << endl;
    }

    return 0;
}


#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <cmath>
#define inf 999999999
#define M 105
#define For(i,a,b) for(int i=(a);i<(b);i++)
#define Me(a,v) memset(a,v,sizeof(a))
using namespace std;
int m, n;
int a[M];
int b[M];

int gcd(int x, int y) {
    return y == 0 ? x : gcd(y, x % y);
}

int main(int argc, char** argv) {
    cin >> n >> m;
    int s, t;

    For(i, 0, n + 1) {
        cin >> a[i];
    }
    For(i, 0, m + 1)
    cin >> b[i];
    if (n < m) {
        cout << "0/1" << endl;
    } else if (n > m) {
        if (a[0] > 0) {
            cout << "Infinity" << endl;
        } else cout << "-Infinity" << endl;
    } else {
        int aa = a[0];
        int bb = b[0];
        int d = gcd(aa, bb);
        aa /= d;
        bb /= d;

        if (bb < 0)
            bb = -bb, aa = -aa;
        if (bb == 1) printf("%d\n", aa);
        else if (aa == 0) printf("0/1\n");
        else
            cout << aa << "/" << bb << endl;
    }
    return 0;
}


#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <cmath>
#define inf 999999999
#define M 105
#define For(i,a,b) for(int i=(a);i<(b);i++)
#define Me(a,v) memset(a,v,sizeof(a))
using namespace std;
int m, n;
int a[M];
int b[M];

int gcd(int x, int y) {
    if (y == 0)
        return x;
    else
        return gcd(y, x % y);
}

int main(int argc, char** argv) {
    cin >> n >> m;
    int s, t;

    For(i, 0, n + 1) {
        cin >> a[i];
    }
    For(i, 0, m + 1)
    cin >> b[i];
    if (n < m) {
        cout << "0/1" << endl;
    } else if (n > m) {
        if (a[0] > 0) {
            cout << "Infinity" << endl;
        } else cout << "-Infinity" << endl;
    } else {
        int aa = a[0];
        int bb = b[0];
        int d = gcd(aa, bb);
        aa /= d;
        bb /= d;
        if (bb < 0)
            bb = -bb, aa = -aa;
        cout << aa << "/" << bb << endl;
    }

    return 0;
}


#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <cmath>
#define inf 999999999
#define M 105
#define For(i,a,b) for(int i=(a);i<(b);i++)
#define Me(a,v) memset(a,v,sizeof(a))
using namespace std;
int m, n;
int a[M];
int b[M];

int gcd(int x, int y) {
    if (y == 0)
        return x;
    else
        return gcd(y, x % y);
}

int main(int argc, char** argv) {
    cin >> n >> m;
    int s, t;
    s = n, t = m;

    For(i, 0, n + 1) {
        cin >> a[i];
    }
    For(i, 0, m + 1)
    cin >> b[i];

    For(i, 0, n + 1) {
        if (a[i] == 0) {
            s--;
        } else
            break;
    }

    For(i, 0, m + 1) {
        if (b[i] == 0) {
            t--;
        } else
            break;
    }
    if (s < t) {
        cout << "0/1" << endl;
    } else if (s > t) {
        if (a[n - s] > 0) {
            cout << "Infinity" << endl;
        } else cout << "-Infinity" << endl;
    } else {
        int aa = a[n - s];
        int bb = b[m - t];
        int d = gcd(aa,bb);
        aa/=d;
        bb/=d;
        if(bb<0)
            bb=-bb,aa=-aa;
        cout<<aa<<"/"<<bb<<endl;
    }

    return 0;
}


#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <cmath>
#define inf 999999999
#define M 105
#define For(i,a,b) for(int i=(a);i<(b);i++)
#define Me(a,v) memset(a,v,sizeof(a))
using namespace std;
int m, n;
int a[M];
int b[M];

int gcd(int x, int y) {
    if (y == 0)
        return x;
    else
        return gcd(y, x % y);
}

int main(int argc, char** argv) {
    cin >> n >> m;
    int s, t;
    s = n, t = m;

    For(i, 0, n + 1) {
        cin >> a[i];
    }
    For(i, 0, m + 1)
    cin >> b[i];

    For(i, 0, n + 1) {
        if (a[i] == 0) {
            n--;
        } else
            break;
    }

    For(i, 0, m + 1) {
        if (b[i] == 0) {
            m--;
        } else
            break;
    }
    if (s < t) {
        cout << "0/1" << endl;
    } else if (s > t) {
        if (a[n - s] > 0) {
            cout << "Infinity" << endl;
        } else cout << "-Infinity" << endl;
    } else {
        int aa = a[n - s];
        int bb = b[m - t];
        int d = gcd(aa,bb);
        cout<<aa/d<<"/"<<bb/d<<endl;
    }

    return 0;
}


#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <cmath>
#define inf 999999999
#define M 105
#define For(i,a,b) for(int i=(a);i<(b);i++)
#define Me(a,v) memset(a,v,sizeof(a))
using namespace std;
int m, n;
int a[M];
int b[M];

int gcd(int x, int y) {
    return y == 0 ? x : gcd(y, x % y);
}

int main(int argc, char** argv) {
    cin >> n >> m;
    int s, t;

    For(i, 0, n + 1) {
        cin >> a[i];
    }
    For(i, 0, m + 1)
    cin >> b[i];
    if (n < m) {
        cout << "0/1" << endl;
    } else if (n > m) {
        if (a[0] * b[0] > 0) {
            cout << "Infinity" << endl;
        } else cout << "-Infinity" << endl;
    } else {
        int aa = a[0];
        int bb = b[0];
        int d = gcd(aa, bb);
        aa /= d;
        bb /= d;

        if (bb < 0)
            bb = -bb, aa = -aa;
        //        if (bb == 1) printf("%d\n", aa);
        //        else if (aa == 0) printf("0/1\n");
        //        else
        cout << aa << "/" << bb << endl;
    }
    return 0;
}


#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <cmath>
#define inf 999999999
#define M 105
#define For(i,a,b) for(int i=(a);i<(b);i++)
#define Me(a,v) memset(a,v,sizeof(a))
using namespace std;
int m, n;
int a[M];
int b[M];

int gcd(int x, int y) {
    return y == 0 ? x : gcd(y, x % y);
}

int main(int argc, char** argv) {
    cin >> n >> m;
    int s, t;

    For(i, 0, n + 1) {
        cin >> a[i];
    }
    For(i, 0, m + 1)
    cin >> b[i];
    if (n < m) {
        cout << "0/1" << endl;
    } else if (n > m) {
        if (a[0] > 0) {
            cout << "Infinity" << endl;
        } else cout << "-Infinity" << endl;
    } else {
        int aa = a[0];
        int bb = b[0];
        int d = gcd(aa, bb);
        aa /= d;
        bb /= d;
        //        if (bb == 1) printf("%d\n", aa);
        //        else if (aa == 0) printf("0/1\n");

        if (bb < 0)
            bb = -bb, aa = -aa;

        cout << aa << "/" << bb << endl;
    }
    return 0;
}


#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <cmath>
#define inf 999999999
#define M 105
#define For(i,a,b) for(int i=(a);i<(b);i++)
#define Me(a,v) memset(a,v,sizeof(a))
using namespace std;
int m, n;
int a[M];
int b[M];

int gcd(int x, int y) {
    if (y == 0)
        return x;
    else
        return gcd(y, x % y);
}

int main(int argc, char** argv) {
    cin >> n >> m;
    int s, t;
    s = n, t = m;

    For(i, 0, n + 1) {
        cin >> a[i];
    }
    For(i, 0, m + 1)
    cin >> b[i];

    For(i, 0, n + 1) {
        if (a[i] == 0) {
            n--;
        } else
            break;
    }

    For(i, 0, m + 1) {
        if (b[i] == 0) {
            m--;
        } else
            break;
    }
    if (s < t) {
        cout << "0/1" << endl;
    } else if (s > t) {
        if (a[n - s] > 0) {
            cout << "Infinity" << endl;
        } else cout << "-Infinity" << endl;
    } else {
        int aa = a[n - s];
        int bb = b[m - t];
        int d = gcd(aa,bb);
        aa/=d;
        bb/=d;
        if(bb<0)
            bb=-bb,aa=-aa;
        cout<<aa<<"/"<<bb<<endl;
    }

    return 0;
}


#include <stdio.h>
#include <stdlib.h> /*        */
#include <algorithm>

using namespace std;

main () {
     int n, m, a, a1, a2, x, md, s;
     scanf ("%d %d", &n, &m);
     scanf ("%d", &a1);
     for (a=1; a<=n; a++)
         scanf ("%d", &x);
     scanf ("%d", &a2);
     for (a=1; a<m; a++)
         scanf ("%d", &x);
     if (n>m) {
        if (a1*a2>0)
           printf ("Infinity");
        else
            printf ("-Infinity");
     }
     if (n<m)
        printf ("0/1");
     if (n==m) {
        md=__gcd(a1, a2);
        a1/=md;
        a2/=md;
        if (a1*a2<0)
           s=-1;
        else
            s=1;
        if (a1<0)
           a1*=-1;
        if (a2<0)
           a2*=-2;
        a1*=s;
        if (a2==1)
           printf ("%d", a1);
        else
            printf ("%d/%d", a1, a2);
     }
     system ("pause");
     return 0;
}


#include <stdio.h>
#include <algorithm>

using namespace std;

main () {
     int n, m, a, a1, a2, x, md, s;
     scanf ("%d %d", &n, &m);
     scanf ("%d", &a1);
     for (a=1; a<=n; a++)
         scanf ("%d", &x);
     scanf ("%d", &a2);
     for (a=1; a<m; a++)
         scanf ("%d", &x);
     if (n>m) {
        if (a1*a2>0)
           printf ("Infinity");
        else
            printf ("-Infinity");
     }
     if (n<m)
        printf ("0/1");
     if (n==m) {
        md=__gcd(a1, a2);
        a1/=md;
        a2/=md;
        if (a1*a2<0)
           s=-1;
        else
            s=1;
        if (a1<0)
           a1*=-1;
        if (a2<0)
           a2*=-1;
        a1*=s;
        if (a2==1)
           printf ("%d", a1);
        else
            printf ("%d/%d", a1, a2);
     }
     return 0;
}


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

using namespace std;

main () {
     int n, m, a, a1, a2, x, md, s;
     scanf ("%d %d", &n, &m);
     scanf ("%d", &a1);
     for (a=1; a<=n; a++)
         scanf ("%d", &x);
     scanf ("%d", &a2);
     for (a=1; a<m; a++)
         scanf ("%d", &x);
     if (n>m) {
        if (a1*a2>0)
           printf ("Infinity");
        else
            printf ("-Infinity");
     }
     if (n<m)
        printf ("0/1");
     if (n==m) {
        md=__gcd(a1, a2);
        a1/=md;
        a2/=md;
        if (a1*a2<0)
           s=-1;
        else
            s=1;
        if (a1<0)
           a1*=-1;
        if (a2<0)
           a2*=-1;
        a1*=s;
        if (a2==1)
           printf ("%d", a1);
        else
            printf ("%d/%d", a1, a2);
     }
     system ("pause");
     return 0;
}


#include <stdio.h>
#include <algorithm>

using namespace std;

main () {
     int n, m, a, a1, a2, x, md, s;
     scanf ("%d %d", &n, &m);
     scanf ("%d", &a1);
     for (a=1; a<=n; a++)
         scanf ("%d", &x);
     scanf ("%d", &a2);
     for (a=1; a<m; a++)
         scanf ("%d", &x);
     if (n>m) {
        if (a1*a2>0)
           printf ("Infinity");
        else
            printf ("-Infinity");
     }
     if (n<m)
        printf ("0/1");
     if (n==m) {
        md=__gcd(a1, a2);
        a1/=md;
        a2/=md;
        if (a1*a2<0)
           s=-1;
        else
            s=1;
        if (a1<0)
           a1*=-1;
        if (a2<0)
           a2*=-1;
        a1*=s;
        printf ("%d/%d", a1, a2);
     }
     return 0;
}


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

using namespace std;

main () {
     int n, m, a, a1, a2, x, md, s;
     scanf ("%d %d", &n, &m);
     scanf ("%d", &a1);
     for (a=1; a<=n; a++)
         scanf ("%d", &x);
     scanf ("%d", &a2);
     for (a=1; a<m; a++)
         scanf ("%d", &x);
     if (n>m) {
        if (a1*a2>0)
           printf ("Infinity");
        else
            printf ("-Infinity");
     }
     if (n<m)
        printf ("0/1");
     if (n==m) {
        md=__gcd(a1, a2);
        a1/=md;
        a2/=md;
        if (a1*a2<0)
           s=-1;
        else
            s=1;
        if (a1<0)
           a1*=-1;
        if (a2<0)
           a2*=-2;
        a1*=s;
        if (a2==1)
           printf ("%d", a1);
        else
            printf ("%d/%d", a1, a2);
     }
     system ("pause");
     return 0;
}


#include <stdio.h>
#include <algorithm>

using namespace std;

main () {
     int n, m, a, a1, a2, x, md, s;
     scanf ("%d %d", &n, &m);
     scanf ("%d", &a1);
     for (a=1; a<=n; a++)
         scanf ("%d", &x);
     scanf ("%d", &a2);
     for (a=1; a<m; a++)
         scanf ("%d", &x);
     if (n>m) {
        if (a1*a2>0)
           printf ("Infinity");
        else
            printf ("-Infinity");
     }
     if (n<m)
        printf ("0/1");
     if (n==m) {
        md=__gcd(a1, a2);
        a1/=md;
        a2/=md;
        if (a1*a2<0)
           s=-1;
        else
            s=1;
        if (a1<0)
           a1*=-1;
        if (a2<0)
           a2*=-2;
        a1*=s;
        if (a2==1)
           printf ("%d", a1);
        else
            printf ("%d/%d", a1, a2);
     }
     return 0;
}


#include <iostream>
#include <cmath>

using namespace std;

int gcd(int u, int v);

int main(){
	int n, m, x, u, v, temp, sign;
	cin>>n>>m;

	int a[n+1], b[m+1];

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

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

	if(n>m){
		if((a[0]>0 && b[0]>0) || (a[0]<0 && b[0]<0)){
			cout<<"Infinity"<<endl;
			return 0;
		} else {
			cout<<"-Infinity"<<endl;
			return 0;
		}
	} else if(n<m){
		cout<<"0/1"<<endl;
		return 0;
	} else {
		u = a[0];
		v = b[0];
		x = gcd(abs(a[0]), abs(b[0]));
	}

	if(u * v >= 0){
		cout<<u/x<<"/"<<v/x<<endl;
	} else {
		cout<<"-"<<u/x<<"/"<<v/x<<endl;
	}

	return 0;
}

int gcd(int u, int v){
	int temp;

	while(v!=0){
		temp = u % v;
		u = v;
		v = temp;
	}

	return u;
}


#include <iostream>

using namespace std;

int gcd(int u, int v);

int main(){
	int n, m, x, u, v, temp, sign;
	cin>>n>>m;

	int a[n+1], b[m+1];

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

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

	if(n>m){
		if((a[0]>0 && b[0]>0) || (a[0]<0 && b[0]<0)){
			cout<<"Infinity"<<endl;
			return 0;
		} else {
			cout<<"-Infinity"<<endl;
			return 0;
		}
	} else if(n<m){
		cout<<"0/1"<<endl;
		return 0;
	} else {
		if((a[0]>0 && b[0]>0) || (a[0]<0 && b[0]<0)){
			if(a[0]<0){
				u = -a[0];
				v = -b[0];
			} else {
				u = a[0];
				v = b[0];
			}
			x = gcd(u, v);
			sign = 1;
		} else {
			if(a[0]>0 && b[0]<0){
				u = a[0];
				v = -b[0];
			} else {
				u = -a[0];
				v = b[0];
			}
			x = gcd(u, v);
			sign = 0;
		}
	}

	if(sign){
		cout<<u/x<<"/"<<v/x<<endl;
	} else {
		cout<<"-"<<u/x<<"/"<<v/x<<endl;
	}

	return 0;
}

int gcd(int u, int v){
	int temp;

	while(v!=0){
		temp = u % v;
		u = v;
		v = temp;
	}

	return u;
}


#include <iostream>
#include <cmath>

using namespace std;

int gcd(int u, int v);

int main(){
	int n, m, x, u, v, temp, sign;
	cin>>n>>m;

	int a[n+1], b[m+1];

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

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

	if(n>m){
		if((a[0]>0 && b[0]>0) || (a[0]<0 && b[0]<0)){
			cout<<"Infinity"<<endl;
			return 0;
		} else {
			cout<<"-Infinity"<<endl;
			return 0;
		}
	} else if(n<m){
		cout<<"0/1"<<endl;
		return 0;
	} else {
		u = a[0];
		v = b[0];
		x = gcd(abs(u), abs(v));
	}

	if(u * v >=0){
		cout<<abs(u)/x<<"/"<<abs(v)/x<<endl;
	} else {
		cout<<"-"<<abs(u)/x<<"/"<<abs(v)/x<<endl;
	}

	return 0;
}

int gcd(int u, int v){
	int temp;

	while(v!=0){
		temp = u % v;
		u = v;
		v = temp;
	}

	return u;
}


#include <iostream>

using namespace std;

int gcd(int u, int v);

int main(){
	int n, m, x, u, v, temp, sign;
	cin>>n>>m;

	int a[n+1], b[m+1];

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

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

	if(n>m){
		if((a[0]>0 && b[0]>0) || (a[0]<0 && b[0]<0)){
			cout<<"Infinity"<<endl;
			return 0;
		} else {
			cout<<"-Infinity"<<endl;
			return 0;
		}
	} else if(n<m){
		cout<<"0/1"<<endl;
	} else {
		if((a[0]>0 && b[0]>0) || (a[0]<0 && b[0]<0)){
			if(a[0]<0){
				u = -a[0];
				v = -b[0];
			} else {
				u = a[0];
				v = b[0];
			}
			x = gcd(u, v);
			sign = 1;
		} else {
			if(a[0]>0 && b[0]<0){
				u = a[0];
				v = -b[0];
			} else {
				u = -a[0];
				v = b[0];
			}
			x = gcd(u, v);
			sign = 0;
		}
	}

	if(sign){
		cout<<u/x<<"/"<<v/x<<endl;
	} else {
		cout<<"-"<<u<<"/"<<v/x<<endl;
	}

	return 0;
}

int gcd(int u, int v){
	int temp;

	while(v!=0){
		temp = u % v;
		u = v;
		v = temp;
	}

	return u;
}


#include <iostream>
#include <cmath>

using namespace std;

int gcd(int u, int v);

int main(){
	int n, m, x, u, v, temp, sign;
	cin>>n>>m;

	int a[n+1], b[m+1];

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

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

	if(n>m){
		if((a[0]>0 && b[0]>0) || (a[0]<0 && b[0]<0)){
			cout<<"Infinity"<<endl;
			return 0;
		} else {
			cout<<"-Infinity"<<endl;
			return 0;
		}
	} else if(n<m){
		cout<<"0/1"<<endl;
		return 0;
	} else {
		u = abs(a[0]);
		b = abs(b[0]);
		x = gcd(u, v);
	}

	if(a[0] * b[0] >=0){
		cout<<u/x<<"/"<<v/x<<endl;
	} else {
		cout<<"-"<<u/x<<"/"<<v/x<<endl;
	}

	return 0;
}

int gcd(int u, int v){
	int temp;

	while(v!=0){
		temp = u % v;
		u = v;
		v = temp;
	}

	return u;
}


#include <iostream>
#include <cmath>

using namespace std;

int gcd(int u, int v);

int main(){
	int n, m, x, u, v, temp, sign;
	cin>>n>>m;

	int a[n+1], b[m+1];

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

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

	if(n>m){
		if((a[0]>0 && b[0]>0) || (a[0]<0 && b[0]<0)){
			cout<<"Infinity"<<endl;
			return 0;
		} else {
			cout<<"-Infinity"<<endl;
			return 0;
		}
	} else if(n<m){
		cout<<"0/1"<<endl;
		return 0;
	} else {
		u = a[0];
		v = b[0];
		x = gcd(abs(u), abs(v));
	}

	if(u * v >=0){
		cout<<abs(u)/x<<"/"<<abs(v)/x<<endl;
	} else {
		cout<<"-"<<u/x<<"/"<<v/x<<endl;
	}

	return 0;
}

int gcd(int u, int v){
	int temp;

	while(v!=0){
		temp = u % v;
		u = v;
		v = temp;
	}

	return u;
}


#include <iostream>

using namespace std;

int gcd(int u, int v);

int main(){
	int n, m, x, u, v, temp, sign;
	cin>>n>>m;

	int a[n+1], b[m+1];

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

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

	if(n>m){
		if((a[0]>0 && b[0]>0) || (a[0]<0 && b[0]<0)){
			cout<<"Infinity"<<endl;
			return 0;
		} else {
			cout<<"-Infinity"<<endl;
			return 0;
		}
	} else if(n<m){
		cout<<"0/1"<<endl;
		return 0;
	} else {
		if((a[0]>0 && b[0]>0) || (a[0]<0 && b[0]<0)){
			if(a[0]<0){
				u = -a[0];
				v = -b[0];
			} else {
				u = a[0];
				v = b[0];
			}
			x = gcd(u, v);
			sign = 1;
		} else {
			if(a[0]>0 && b[0]<0){
				u = a[0];
				v = -b[0];
			} else {
				u = -a[0];
				v = b[0];
			}
			x = gcd(u, v);
			sign = 0;
		}
	}

	if(sign){
		cout<<u/x<<"/"<<v/x<<endl;
	} else {
		cout<<"-"<<u<<"/"<<v/x<<endl;
	}

	return 0;
}

int gcd(int u, int v){
	int temp;

	while(v!=0){
		temp = u % v;
		u = v;
		v = temp;
	}

	return u;
}


#include <iostream>
#include <cmath>

using namespace std;

int gcd(int u, int v);

int main(){
	int n, m, x, u, v, temp, sign;
	cin>>n>>m;

	int a[n+1], b[m+1];

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

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

	if(n>m){
		if((a[0]>0 && b[0]>0) || (a[0]<0 && b[0]<0)){
			cout<<"Infinity"<<endl;
			return 0;
		} else {
			cout<<"-Infinity"<<endl;
			return 0;
		}
	} else if(n<m){
		cout<<"0/1"<<endl;
		return 0;
	} else {
		u = a[0];
		b = b[0];
		x = gcd(abs(u), abs(v));
	}

	if(u * v >=0){
		cout<<abs(u)/x<<"/"<<abs(v)/x<<endl;
	} else {
		cout<<"-"<<u/x<<"/"<<v/x<<endl;
	}

	return 0;
}

int gcd(int u, int v){
	int temp;

	while(v!=0){
		temp = u % v;
		u = v;
		v = temp;
	}

	return u;
}


#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int main()
{
int n,m;cin>>n>>m;int a[n],b[m];
for(int i=0;i<=n;i++) cin>>a[i];
for(int i=0;i<=m;i++) cin>>b[i];
if(n>m)
{
if(a[0]<0&&b[0]<0) cout<<"Infinity";
else if(a[0]>0&&b[0]>0) cout<<"Infinity";
else cout<<"-Infinity";}
else if(n<m)
cout<<"0/1";
else
{for(int i=2;i<=abs(a[0])||i<=abs(b[0]);i++)
{while(a[0]%i==0&&b[0]%i==0)
{a[0]/=i;b[0]/=i;}}
if(a[0]<0&&b[0]<0)
cout<<abs(a[0])<<'/'<<abs(b[0]);
else if(a[0]>0&&b[0]>0)
cout<<a[0]<<'/'<<b[0];
else
cout<<'-'<<abs(a[0])<<'/'<<abs(b[0]);
}
return 0;
}


#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int main()
{
int n,m;cin>>n>>m;int a[n],b[m];
for(int i=0;i<=n;i++) cin>>a[i];
for(int i=0;i<=m;i++) cin>>b[i];
if(n>m)
{
if(a[0]<0&&b[0]<0) cout<<"Infinity";
else if(a[0]>0&&b[0]>0) cout<<"Infinity";
else cout<<"-Infinity";}
else if(n<m)
cout<<"0/1";
else
{for(int i=2;i<=a[0]||i<=b[0];i++)
{if(a[0]%i==0&&b[0]%i==0)
{a[0]/=i;b[0]/=i;}}
if(a[0]<0&&b[0]<0)
cout<<abs(a[0])<<'/'<<abs(b[0]);
else if(a[0]>0&&b[0]>0)
cout<<a[0]<<'/'<<b[0];
else
cout<<'-'<<abs(a[0])<<'/'<<abs(b[0]);
}
return 0;
}


#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int main()
{
int n,m;cin>>n>>m;int a[n],b[m];
for(int i=0;i<=n;i++) cin>>a[i];
for(int i=0;i<=m;i++) cin>>b[i];
if(n>m)
{
if(a[0]<0&&b[0]<0) cout<<"Infinity";
else if(a[0]>0&&b[0]>0) cout<<"Infinity";
else cout<<"-Infinity";}
else if(n<m)
cout<<"0/1";
else
{for(int i=2;i<a[0]||i<b[0];i++)
{if(a[0]%i==0&&b[0]%i==0)
{a[0]/=i;b[0]/=i;}}
if(a[0]<0&&b[0]<0)
cout<<a[0]<<'/'<<b[0];
else if(a[0]>0&&b[0]>0)
cout<<a[0]<<'/'<<b[0];
else
cout<<'-'<<abs(a[0])<<'/'<<abs(b[0]);
}
return 0;
}


#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int main()
{
int n,m;cin>>n>>m;int a[n],b[m];
for(int i=0;i<=n;i++) cin>>a[i];
for(int i=0;i<=m;i++) cin>>b[i];
if(n>m)
{
if(a[0]<0&&b[0]<0) cout<<"Infinity";
else if(a[0]>0&&b[0]>0) cout<<"Infinity";
else cout<<"-Infinity";}
else if(n<m)
cout<<"0/1";
else
{for(int i=2;i<=a[0]||i<=b[0];i++)
{while(a[0]%i==0&&b[0]%i==0)
{a[0]/=i;b[0]/=i;}}
if(a[0]<0&&b[0]<0)
cout<<abs(a[0])<<'/'<<abs(b[0]);
else if(a[0]>0&&b[0]>0)
cout<<a[0]<<'/'<<b[0];
else
cout<<'-'<<abs(a[0])<<'/'<<abs(b[0]);
}
return 0;
}


#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int main()
{
int n,m;cin>>n>>m;int a[n],b[m];
for(int i=0;i<=n;i++) cin>>a[i];
for(int i=0;i<=m;i++) cin>>b[i];
if(n>m)
{
if(a[0]<0&&b[0]<0) cout<<"Infinity";
else if(a[0]>0&&b[0]>0) cout<<"Infinity";
else cout<<"-Infinity";}
else if(n<m)
cout<<"0/1";
else
{for(int i=2;i<a[0]||i<b[0];i++)
{if(a[0]%i==0&&b[0]%i==0)
{a[0]/=i;b[0]/=i;}}
if(a[0]<0&&b[0]<0)
cout<<abs(a[0])<<'/'<<abs(b[0]);
else if(a[0]>0&&b[0]>0)
cout<<a[0]<<'/'<<b[0];
else
cout<<'-'<<abs(a[0])<<'/'<<abs(b[0]);
}
return 0;
}


#include<iostream>
#define pause system("PAUSE")
#define rtrn return 0
#define oR ||
#define anD &&
#define LL long long
#define rep(i,j,n) for(int i=j;i<n;i++)
#define whl(i,j) while(i<j)
#define eL endl
using namespace std;
LL gcd(LL m, LL n) {
	if(n==0)return m;
	else return gcd(n,m%n);
}
int main()
{
	LL a[111],b[111],n,m,d;
	cin>>n>>m;
	rep(i,0,n+1)cin>>a[i];
	rep(i,0,m+1)cin>>b[i];
	if(n>m)cout<<((a[0]>0)?"Infinity":"-Infinity")<<eL;
	else if(n<m){
		cout<<((b[0]>0)?"0/1":"-0/1")<<eL;
	}
	else {
		if(b[0]<0){
			a[0]=-a[0];
			b[0]=b[0]*(-1);
		}
		d=gcd(((a[0]>0)?a[0]:-a[0]),b[0]);
		cout<<a[0]/d<<'/'<<b[0]/d<<eL;

	}
	rtrn;
}


#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<cstring>
#include<utility>
#include<valarray>
#include<vector>
#define pause system("PAUSE");
#define rtrn return 0;
#define oR ||
#define anD &&
#define LL long long
#define rep(i,j,n) for(int i=j;i<n;i++)
#define whl(i,j) while(i<j)
#define eL endl
using namespace std;
int gcd(int m, int n) {
	if(n==0)return m;
	else return gcd(n,m%n);
}
int main()
{
	int a[111],b[111],n,m,d;
	cin>>n>>m;
	rep(i,0,n+1)cin>>a[i];
	rep(i,0,m+1)cin>>b[i];
	if(n>m)cout<<((a[0]>0)?"Infinity":"-Infinity")<<eL;
	else if(n<m)cout<<"0/1"<<eL;
	else if(n==m){
		d=gcd(((a[0]>0)?a[0]:-a[0]),((b[0]>0)?b[0]:-b[0]));
		if(d<0)d=-d;
		if(b[0]<0){ a[0]=-a[0]; b[0]=-b[0]; }
		cout<<a[0]/d<<'/'<<b[0]/d<<eL;
	}
	rtrn
}


#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<cstring>
#include<utility>
#include<valarray>
#include<vector>
#define pause system("PAUSE");
#define rtrn return 0;
#define oR ||
#define anD &&
#define LL long long
#define rep(i,j,n) for(int i=j;i<n;i++)
#define whl(i,j) while(i<j)
#define eL endl
using namespace std;
int main()
{
	LL a[100],b[100],n,m;
	cin>>n>>m;
	rep(i,0,n+1)cin>>a[i];
	rep(i,0,m+1)cin>>b[i];
	if(n>m)cout<<((a[0]>0)?"Infinity":"-Infinity")<<eL;
	if(n<m)cout<<"0/1"<<eL;
	if(n==m){
		if(b[0]<0){ a[0]=-a[0]; b[0]=-b[0]; }
		cout<<a[0]<<'/'<<b[0]<<eL;
	}
	rtrn
}


#include<iostream>
#define pause system("PAUSE")
#define rtrn return 0
#define oR ||
#define anD &&
#define LL long long
#define rep(i,j,n) for(int i=j;i<n;i++)
#define whl(i,j) while(i<j)
#define eL endl
using namespace std;
LL gcd(LL m, LL n) {
	if(n==0)return m;
	else return gcd(n,m%n);
}
int main()
{
	LL a[111],b[111],n,m,d;
	cin>>n>>m;
	rep(i,0,n+1)cin>>a[i];
	rep(i,0,m+1)cin>>b[i];
	if(n>m)cout<<((a[0]*b[0]>0)?"Infinity":"-Infinity")<<eL;
	else if(n<m){
		cout<<((b[0]>0)?"0/1":"-0/1")<<eL;
	}
	else {
		if(b[0]<0){
			a[0]=-a[0];
			b[0]=b[0]*(-1);
		}
		d=gcd(((a[0]>0)?a[0]:-a[0]),b[0]);
		cout<<a[0]/d<<'/'<<b[0]/d<<eL;

	}
	rtrn;
}


#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<cstring>
#include<utility>
#include<valarray>
#include<vector>
#define pause system("PAUSE");
#define rtrn return 0;
#define oR ||
#define anD &&
#define LL long long
#define rep(i,j,n) for(int i=j;i<n;i++)
#define whl(i,j) while(i<j)
#define eL endl
using namespace std;
int main()
{
	LL a[100],b[100],n,m;
	cin>>n>>m;
	rep(i,0,n+1)cin>>a[i];
	rep(i,0,m+1)cin>>b[i];
	if(n>m)cout<<((a[0]>0)?"Infinity":"-Infinity")<<eL;
	if(n<m)cout<<"0/1"<<eL;
	if(n==m){
		if(b[0]<0){ a[0]=-a[0]; b[0]=-b[0]; }
		cout<<a[0]<<'/'<<b[0]<<eL;
	}
	pause rtrn
}


#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<cstring>
#include<utility>
#include<valarray>
#include<vector>
#define pause system("PAUSE");
#define rtrn return 0;
#define oR ||
#define anD &&
#define LL long long
#define rep(i,j,n) for(int i=j;i<n;i++)
#define whl(i,j) while(i<j)
#define eL endl
using namespace std;
int gcd(int m, int n) {
	if(n==0)return m;
	else return gcd(n,m%n);
}
int main()
{
	int a[111],b[111],n,m,d;
	cin>>n>>m;
	rep(i,0,n+1)cin>>a[i];
	rep(i,0,m+1)cin>>b[i];
	if(n>m)cout<<((a[0]>0)?"Infinity":"-Infinity")<<eL;
	if(n<m)cout<<"0/1"<<eL;
	if(n==m){
		d=gcd((a[0]>0)?a[0]:-a[0],(b[0]>0)?b[0]:-b[0]);
		if(b[0]<0){ a[0]=-a[0]; b[0]=-b[0]; }
		cout<<a[0]/d<<'/'<<b[0]/d<<eL;
	}
	rtrn
}


#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<cstring>
#include<utility>
#include<valarray>
#include<vector>
#define pause system("PAUSE");
#define rtrn return 0;
#define oR ||
#define anD &&
#define LL long long
#define rep(i,j,n) for(int i=j;i<n;i++)
#define whl(i,j) while(i<j)
#define eL endl
using namespace std;
int gcd(int m, int n) {
	if(n==0)return m;
	else return gcd(n,m%n);
}
int main()
{
	int a[111],b[111],n,m,d;
	cin>>n>>m;
	rep(i,0,n+1)cin>>a[i];
	rep(i,0,m+1)cin>>b[i];
	if(n>m)cout<<((a[0]>0)?"Infinity":"-Infinity")<<eL;
	else if(n<m)cout<<"0/1"<<eL;
	else if(n==m){
		d=gcd(((a[0]>0)?a[0]:-a[0]),((b[0]>0)?b[0]:-b[0]));
		if(d<0)d=-d;
		if(b[0]<0){ a[0]=-a[0]; b[0]=-b[0]; }
		if(b[0]/d!=1)cout<<a[0]/d<<'/'<<b[0]/d<<eL;
		else cout<<a[0]/d<<eL;
	}
	rtrn
}


#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<cstring>
#include<utility>
#include<valarray>
#include<vector>
#define pause system("PAUSE")
#define rtrn return 0
#define oR ||
#define anD &&
#define LL long long
#define rep(i,j,n) for(int i=j;i<n;i++)
#define whl(i,j) while(i<j)
#define eL endl
using namespace std;
int gcd(int m, int n) {
	if(n==0)return m;
	else return gcd(n,m%n);
}
int main()
{
	int a[111],b[111],n,m,d;
	cin>>n>>m;
	rep(i,0,n+1)cin>>a[i];
	rep(i,0,m+1)cin>>b[i];
	if(n>m)cout<<((a[0]>0)?"Infinity":"-Infinity")<<eL;
	else if(n<m)cout<<"0/1"<<eL;
	else if(n==m){
		if(b[0]<0){ a[0]=-a[0]; b[0]=-b[0]; }
		d=gcd(((a[0]>0)?a[0]:-a[0]),b[0]);
		if(b[0]/d!=1)cout<<a[0]/d<<'/'<<b[0]/d<<eL;
		else cout<<a[0]/d;

	}
	rtrn;
}


#include<iostream>
#define pause system("PAUSE")
#define rtrn return 0
#define oR ||
#define anD &&
#define LL long long
#define rep(i,j,n) for(int i=j;i<n;i++)
#define whl(i,j) while(i<j)
#define eL endl
using namespace std;
LL gcd(LL m, LL n) {
	if(n==0)return m;
	else return gcd(n,m%n);
}
int main()
{
	LL a[111],b[111],n,m,d;
	cin>>n>>m;
	rep(i,0,n+1)cin>>a[i];
	rep(i,0,m+1)cin>>b[i];
	if(n>m)cout<<((a[0]*b[0]>0)?"Infinity":"-Infinity")<<eL;
	else if(n<m){
		cout<<"0/1"<<eL;
	}
	else {
		if(b[0]<0){
			a[0]=-a[0];
			b[0]=b[0]*(-1);
		}
		d=gcd(((a[0]>0)?a[0]:-a[0]),b[0]);
		cout<<a[0]/d<<'/'<<b[0]/d<<eL;

	}
	rtrn;
}


#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<cstring>
#include<utility>
#include<valarray>
#include<vector>
#define pause system("PAUSE");
#define rtrn return 0;
#define oR ||
#define anD &&
#define LL long long
#define rep(i,j,n) for(int i=j;i<n;i++)
#define whl(i,j) while(i<j)
#define eL endl
using namespace std;
int gcd(int m, int n) {
	if(n==0)return m;
	else return gcd(n,m%n);
}
int main()
{
	LL a[100],b[100],n,m,d;
	cin>>n>>m;
	rep(i,0,n+1)cin>>a[i];
	rep(i,0,m+1)cin>>b[i];
	if(n>m)cout<<((a[0]>0)?"Infinity":"-Infinity")<<eL;
	if(n<m)cout<<"0/1"<<eL;
	if(n==m){
		d=gcd((a[0]>0)?a[0]:-a[0],(b[0]>0)?b[0]:-b[0]);
		if(b[0]<0){ a[0]=-a[0]; b[0]=-b[0]; }
		cout<<a[0]/d<<'/'<<b[0]/d<<eL;
	}
	rtrn
}


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

using namespace std;

typedef long long ll;

int gcd1(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd1(b, a%b);
}

int gcd(int a, int b) {
	if (b > a) {
		return gcd1(b,a);
	}
	return gcd1(a, b);
}

int main(int argc,char** argv) {
	ll N,M;
	int coeff1[101];
	int coeff2[101];

	cin >> N >> M;
	for (int i=0; i<N+1; i++) {
		cin >> coeff1[i];
	}
	for (int i=0; i<M+1; i++) {
		cin >> coeff2[i];
	}

	if (N > M) {
		if (coeff1[0] < 0) {
			cout << "-Infinity";
		} else {
			cout << "Infinity";
		}
	} else if (N<M) {
		cout << "0/1";
	} else {
		// deg1 == deg2
		bool sign = (coeff1[0] * coeff2[0]) < 0;
		if (coeff1[0] < 0) {
			coeff1[0] = -coeff1[0];
		}
		if (coeff2[0] < 0) {
			coeff2[0] = -coeff2[0];
		}
		ll g = gcd(coeff1[0], coeff2[0]);
		coeff1[0]  /= g;
		coeff2[0] /= g;
		if (sign) {
			cout << "-";
		}
		if (coeff2[0] == 1) {
			cout << coeff1[0];
		} else {
			cout << coeff1[0] << "/" << coeff2[0];
		}
	}

	return 0;
}


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

using namespace std;

typedef long long ll;

int gcd1(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd1(b, a%b);
}

int gcd(int a, int b) {
	if (b > a) {
		return gcd1(b,a);
	}
	return gcd1(a, b);
}

int main(int argc,char** argv) {
	ll N,M;
	int coeff1[101];
	int coeff2[101];

	cin >> N >> M;
	for (int i=0; i<N+1; i++) {
		cin >> coeff1[i];
	}
	for (int i=0; i<M+1; i++) {
		cin >> coeff2[i];
	}

	if (N > M) {
		if (coeff1[0] < 0) {
			cout << "-Infinity";
		} else {
			cout << "Infinity";
		}
	} else if (N<M) {
		cout << "0/1";
	} else {
		// deg1 == deg2
		bool sign = (coeff1[0] * coeff2[0]) < 0;
		if (coeff1[0] < 0) {
			coeff1[0] = -coeff1[0];
		}
		if (coeff2[0] < 0) {
			coeff2[0] = -coeff2[0];
		}
		ll g = gcd(coeff1[0], coeff2[0]);
		if (sign) {
			cout << "-";
		}
		if (coeff2[0] == 1) {
			cout << coeff1[0];
		} else {
			cout << coeff1[0]/g << "/" << coeff2[0]/g;
		}
	}

	return 0;
}


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

using namespace std;

typedef long long ll;

int main(int argc,char** argv) {
	ll N,M;
	int coeff1[101];
	int coeff2[101];

	cin >> N >> M;
	for (int i=0; i<N+1; i++) {
		cin >> coeff1[i];
	}
	for (int i=0; i<M+1; i++) {
		cin >> coeff2[i];
	}

	if (N > M) {
		if (coeff1[0] < 0) {
			cout << "-Infinity";
		} else {
			cout << "Infinity";
		}
	} else if (N<M) {
		cout << "0/1";
	} else {
		// deg1 == deg2
		cout << coeff1[0] << "/" << coeff2[0];
	}

	return 0;
}


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

using namespace std;

typedef long long ll;

int gcd1(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd1(b, a%b);
}

int gcd(int a, int b) {
	if (b > a) {
		return gcd1(b,a);
	}
	return gcd1(a, b);
}

int main(int argc,char** argv) {
	ll N,M;
	int coeff1[101];
	int coeff2[101];

	cin >> N >> M;
	for (int i=0; i<N+1; i++) {
		cin >> coeff1[i];
	}
	for (int i=0; i<M+1; i++) {
		cin >> coeff2[i];
	}

	if (N > M) {
		if (coeff1[0] < 0) {
			cout << "-Infinity";
		} else {
			cout << "Infinity";
		}
	} else if (N<M) {
		cout << "0/1";
	} else {
		// deg1 == deg2
		bool sign = (coeff1[0] * coeff2[0]) < 0;
		if (coeff1[0] < 0) {
			coeff1[0] = -coeff1[0];
		}
		if (coeff2[0] < 0) {
			coeff2[0] = -coeff2[0];
		}
		ll g = gcd(coeff1[0], coeff2[0]);
		if (sign) {
			cout << "-";
		}
		if (coeff1[0] == coeff2[0]) {
			cout << "1";
		} else {
			cout << coeff1[0]/g << "/" << coeff2[0]/g;
		}
	}

	return 0;
}


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

using namespace std;

typedef long long ll;

ll gcd1(ll a, ll b) {
	if (b == 0) {
		return a;
	}
	return gcd1(b, a%b);
}

ll gcd(ll a, ll b) {
	if (a < 0) {
		a = -a;
	}
	if (b < 0) {
		b = -b;
	}
	if (b > a) {
		return gcd1(b,a);
	}
	return gcd1(a, b);
}

int main(int argc,char** argv) {
	ll N,M;
	int coeff1[101];
	int coeff2[101];

	cin >> N >> M;
	for (int i=0; i<N+1; i++) {
		cin >> coeff1[i];
	}
	for (int i=0; i<M+1; i++) {
		cin >> coeff2[i];
	}

	if (N > M) {
		if (coeff1[0] < 0) {
			cout << "-Infinity";
		} else {
			cout << "Infinity";
		}
	} else if (N<M) {
		cout << "0/1";
	} else {
		// deg1 == deg2
		ll g = gcd(coeff1[0], coeff2[0]);
		cout << coeff1[0]/g << "/" << coeff2[0]/g;
	}

	return 0;
}


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

using namespace std;

typedef long long ll;

int gcd1(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd1(b, a%b);
}

int gcd(int a, int b) {
	if (b > a) {
		return gcd1(b,a);
	}
	return gcd1(a, b);
}

int main(int argc,char** argv) {
	ll N,M;
	int coeff1[101];
	int coeff2[101];

	cin >> N >> M;
	for (int i=0; i<N+1; i++) {
		cin >> coeff1[i];
	}
	for (int i=0; i<M+1; i++) {
		cin >> coeff2[i];
	}

	if (N > M) {
		if (coeff1[0] < 0) {
			cout << "-Infinity";
		} else {
			cout << "Infinity";
		}
	} else if (N<M) {
		cout << "0/1";
	} else {
		// deg1 == deg2
		bool sign = (coeff1[0] * coeff2[0]) < 0;
		if (coeff1[0] < 0) {
			coeff1[0] = -coeff1[0];
		}
		if (coeff2[0] < 0) {
			coeff2[0] = -coeff2[0];
		}
		ll g = gcd(coeff1[0], coeff2[0]);
		if (sign) {
			cout << "-";
		}
		cout << coeff1[0]/g << "/" << coeff2[0]/g;
	}

	return 0;
}


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

using namespace std;

typedef long long ll;

int gcd1(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd1(b, a%b);
}

int gcd(int a, int b) {
	if (b > a) {
		return gcd1(b,a);
	}
	return gcd1(a, b);
}

int main(int argc,char** argv) {
	ll N,M;
	int coeff1[101];
	int coeff2[101];

	cin >> N >> M;
	for (int i=0; i<N+1; i++) {
		cin >> coeff1[i];
	}
	for (int i=0; i<M+1; i++) {
		cin >> coeff2[i];
	}

	if (N > M) {
		if (coeff1[0] < 0) {
			cout << "-Infinity";
		} else {
			cout << "Infinity";
		}
	} else if (N<M) {
		cout << "0/1";
	} else {
		// deg1 == deg2
		bool sign = (coeff1[0] * coeff2[0]) < 0;
		if (coeff1[0] < 0) {
			coeff1[0] = -coeff1[0];
		}
		if (coeff2[0] < 0) {
			coeff2[0] = -coeff2[0];
		}
		int g = gcd(coeff1[0], coeff2[0]);
		coeff1[0]  /= g;
		coeff2[0]  /= g;
		if (sign) {
			cout << "-";
		}
		/*
		if (coeff2[0] == 1) {
			cout << coeff1[0];
		} else {
			cout << coeff1[0] << "/" << coeff2[0];
		}*/
		cout << coeff1[0] << "/" << coeff2[0];

	}

	return 0;
}


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

using namespace std;

typedef long long ll;

ll gcd1(ll a, ll b) {
	if (b == 0) {
		return a;
	}
	return gcd1(b, a%b);
}

ll gcd(ll a, ll b) {
	if (b > a) {
		return gcd1(b,a);
	}
	return gcd1(a, b);
}

int main(int argc,char** argv) {
	ll N,M;
	int coeff1[101];
	int coeff2[101];

	cin >> N >> M;
	for (int i=0; i<N+1; i++) {
		cin >> coeff1[i];
	}
	for (int i=0; i<M+1; i++) {
		cin >> coeff2[i];
	}

	if (N > M) {
		if (coeff1[0] < 0) {
			cout << "-Infinity";
		} else {
			cout << "Infinity";
		}
	} else if (N<M) {
		cout << "0/1";
	} else {
		// deg1 == deg2
		bool sign = (coeff1[0] * coeff2[0]) < 0;
		if (coeff1[0] < 0) {
			coeff1[0] = -coeff1[0];
		}
		if (coeff2[0] < 0) {
			coeff2[0] = -coeff2[0];
		}
		ll g = gcd(coeff1[0], coeff2[0]);
		if (sign) {
			cout << "-";
		}
		cout << coeff1[0]/g << "/" << coeff2[0]/g;
	}

	return 0;
}


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

using namespace std;

typedef long long ll;

int gcd1(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd1(b, a%b);
}

int gcd(int a, int b) {
	if (b > a) {
		return gcd1(b,a);
	}
	return gcd1(a, b);
}

int main(int argc,char** argv) {
	ll N,M;
	int coeff1[101];
	int coeff2[101];

	cin >> N >> M;
	for (int i=0; i<N+1; i++) {
		cin >> coeff1[i];
	}
	for (int i=0; i<M+1; i++) {
		cin >> coeff2[i];
	}

	if (N > M) {
		if (coeff1[0] * coeff2[0] < 0) {
			cout << "-Infinity" << endl;
		} else {
			cout << "Infinity" << endl;
		}
	} else if (N<M) {
		cout << "0/1" << endl;
	} else {
		// deg1 == deg2
		bool sign = (coeff1[0] * coeff2[0]) < 0;
		if (coeff1[0] < 0) {
			coeff1[0] = -coeff1[0];
		}
		if (coeff2[0] < 0) {
			coeff2[0] = -coeff2[0];
		}
		int g = gcd(coeff1[0], coeff2[0]);
		coeff1[0]  /= g;
		coeff2[0]  /= g;
		if (sign) {
			cout << "-";
		}
		/*
		if (coeff2[0] == 1) {
			cout << coeff1[0];
		} else {
			cout << coeff1[0] << "/" << coeff2[0];
		}*/
		cout << coeff1[0] << "/" << coeff2[0] << endl;
	}

	return 0;
}


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

using namespace std;

typedef long long ll;

ll gcd1(ll a, ll b) {
	if (b == 0) {
		return a;
	}
	return gcd1(b, a%b);
}

ll gcd(ll a, ll b) {
	if (a < 0) {
		a = -a;
	}
	if (b < 0) {
		b = -b;
	}
	if (b > a) {
		return gcd1(b,a);
	}
	return gcd1(a, b);
}

int main(int argc,char** argv) {
	ll N,M;
	int coeff1[101];
	int coeff2[101];

	cin >> N >> M;
	for (int i=0; i<N+1; i++) {
		cin >> coeff1[i];
	}
	for (int i=0; i<M+1; i++) {
		cin >> coeff2[i];
	}

	if (N > M) {
		if (coeff1[0] < 0) {
			cout << "-Infinity";
		} else {
			cout << "Infinity";
		}
	} else if (N<M) {
		cout << "0/1";
	} else {
		// deg1 == deg2
		bool sign = (coeff1[0] ^ coeff2[0]) < 0;
		if (coeff1[0] < 0) {
			coeff1[0] = -coeff1[0];
		}
		if (coeff2[0] < 0) {
			coeff2[0] = -coeff2[0];
		}
		ll g = gcd(coeff1[0], coeff2[0]);
		if (sign) {
			cout << "-";
		}
		cout << coeff1[0]/g << "/" << coeff2[0]/g;
	}

	return 0;
}


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

using namespace std;

typedef long long ll;

int gcd1(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd1(b, a%b);
}

int gcd(int a, int b) {
	if (b > a) {
		return gcd1(b,a);
	}
	return gcd1(a, b);
}

int main(int argc,char** argv) {
	ll N,M;
	int coeff1[101];
	int coeff2[101];

	cin >> N >> M;
	for (int i=0; i<N+1; i++) {
		cin >> coeff1[i];
	}
	for (int i=0; i<M+1; i++) {
		cin >> coeff2[i];
	}

	if (N > M) {
		if (coeff1[0] < 0) {
			cout << "-Infinity" << endl;
		} else {
			cout << "Infinity" << endl;
		}
	} else if (N<M) {
		cout << "0/1" << endl;
	} else {
		// deg1 == deg2
		bool sign = (coeff1[0] * coeff2[0]) < 0;
		if (coeff1[0] < 0) {
			coeff1[0] = -coeff1[0];
		}
		if (coeff2[0] < 0) {
			coeff2[0] = -coeff2[0];
		}
		int g = gcd(coeff1[0], coeff2[0]);
		coeff1[0]  /= g;
		coeff2[0]  /= g;
		if (sign) {
			cout << "-";
		}
		/*
		if (coeff2[0] == 1) {
			cout << coeff1[0];
		} else {
			cout << coeff1[0] << "/" << coeff2[0];
		}*/
		cout << coeff1[0] << "/" << coeff2[0] << endl;

	}

	return 0;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<cmath>
#include<algorithm>
#include<fstream>
#define MAXN 5000
using namespace std;
typedef long long int ll;
typedef __int64 i64;

int gcd(int a, int b)
{
  if (min(abs(a),abs(b)) == 0)return max(abs(a),abs(b));
  return gcd(abs(b),abs(a)%abs(b));
}

int main()
{
  //freopen("text.txt","r",stdin);
  //freopen("myresult.txt","w+",stdout);
  int n,m;
  int q[105],b[105];
  cin>>n>>m;
  for (int i(0); i<n+1; ++i)cin>>q[i];
  for (int j(0); j<m+1; ++j)cin>>b[j];
  if (n>m) {
    if (q[0]<0)cout<<'-';
    cout<<"Infinity"<<endl;
  } else {
    if (n == m) {
      int temp = gcd(q[0],b[0]);
      if (q[0]*b[0]<0)cout<<'-';
      cout<<abs(q[0])/temp<<'/'<<abs(b[0])/temp<<endl;
    } else {
      cout<<"0/1"<<endl;
    }
  }
  //system("pause");
  return 0;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<cmath>
#include<algorithm>
#include<fstream>
#define MAXN 5000
using namespace std;
typedef long long int ll;
typedef __int64 i64;

int gcd(int a, int b)
{
  if (min(abs(a),abs(b)) == 0)return max(abs(a),abs(b));
  return gcd(abs(b),abs(a)%abs(b));
}

int main()
{
  //freopen("text.txt","r",stdin);
  //freopen("myresult.txt","w+",stdout);
  int n,m;
  int q[103],b[103];
  cin>>n>>m;
  for (int i(0); i<n+1; ++i)cin>>q[i];
  for (int j(0); j<m+1; ++j)cin>>b[j];
  if (n>m) {
    if (q[0]<0)cout<<"-";
    cout<<"Infinity"<<endl;
  } else {
    if (n == m) {
      int temp = gcd(q[0],b[0]);
      if (q[0]*b[0]<0)cout<<"-";
      cout<<abs(q[0])/temp<<"/"<<abs(b[0])/temp<<endl;
    } else {
      cout<<"0/1"<<endl;
    }
  }
  //system("pause");
  return 0;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<cmath>
#include<algorithm>
#include<fstream>
#define MAXN 5000
using namespace std;
typedef long long int ll;
typedef __int64 i64;

int gcd(int a, int b)
{
  if (min(abs(a),abs(b)) == 0)return max(abs(a),abs(b));
  return gcd(abs(b),abs(a)%abs(b));
}

int main()
{
  //freopen("text.txt","r",stdin);
  //freopen("myresult.txt","w+",stdout);
  int n,m;
  int q[105],b[105];
  cin>>n>>m;
  for (int i(0); i<n+1; ++i)cin>>q[i];
  for (int j(0); j<m+1; ++j)cin>>b[j];
  if (n>m) {
    if (q[0]*b[0]<0)cout<<'-';
    cout<<"Infinity"<<endl;
  } else {
    if (n == m) {
      int temp = gcd(q[0],b[0]);
      if (q[0]*b[0]<0)cout<<'-';
      cout<<abs(q[0])/temp<<'/'<<abs(b[0])/temp<<endl;
    } else {
      cout<<"0/1"<<endl;
    }
  }
  //system("pause");
  return 0;
}