/*                                بِسْمِ اللَّـهِ الرَّحْمَـٰنِ الرَّحِيمِ

                                    ( إِنِ الْحُكْمُ إِلَّا لِلَّهِ )

*/
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef unsigned long long ull;
typedef long double ld;
const long double pi=acos(-1);
#define x           first
#define y           second
#define read(n,a)   for(int i=0;i<n;i++)cin>>a[i];
#define rep(i,z,n)  for(ll i=z;i<n;i++)
#define rrep(i,z,n) for(ll i=z-1;i>=n;i--)
#define all(v)      v.begin(),v.end()
#define clr(v,d)    memset(v,d,sizeof(v));


ll  a[3002][5];
ll  b[200002];

//int dx[] = {0, 0, 1,1, 1,-1,-1,-1};
//int dy[] = {1,-1, 0,1,-1, 0,1 ,-1};
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};

string s, ss;

ll n,m,k,w;
ll  ans ,ans1;
ll mod = 1e9 +7;

bool can(ll x)
{
    set<int>s;
    rep(i,0,n)
    {
        int bit = 0;
        rep(j,0,5)bit<<=1 , bit|=a[i][j]>=x;
        s.insert(bit);
    }
    for(auto i : s)for(auto j : s )for(auto k : s)if( (i|j|k) == 31)return 1;
    return 0;
}
int main()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t=1;
    //cin>>t;
    while(t--)
    {
        cin>>n;
        rep(i,0,n)rep(j,0,5)cin>>a[i][j];

        ll l = 0 , r= 1e9 , md;
        while(l<=r)
        {
            md=(l+r)/2;
            if(can(md))ans=md,l=md+1;
            else r=md-1;
        }
        cout<<ans;
    }
    return 0;
}

#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define pdd pair<double,double>
#define pii pair<int,int>
#define pll pair<LL,LL>
#define mp make_pair
#define LL long long
#define ULL unsigned long long
#define sqr(x) ((x)*(x))
#define pi acosl(-1)
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
using namespace std;
#define Point pdd
#define Polygon vector<Point>
#define Line pair<Point,Point>

void solve() {
    LL A, B, W;
    cin >> A >> B >> W;
    W *= 1000;
    LL mn = INT_MAX, mx = INT_MIN;
    for(LL i = 1; i <= W; i++){
        LL avg = W / i, left = W % i;
        if(avg < A || (left && avg >= B) || avg > B){
            continue;
        }
        mn = min(i, mn);
        mx = max(i, mx);
    }
    if(mn == INT_MAX){
        cout << "UNSATISFIABLE";
    }else{
        cout << mn << ' ' << mx;
    }
}

int main() {
//    solve();
    int T = 1;
    //cin >> T;
    for (int i = 0; i < T; ++i) {
        solve();
    }
    return 0;
}
