#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
using ll = long long;
struct Edge
{
    ll to;
    ll cost;
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, ll>;
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), v.end()
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = LLONG_MAX;
const int MAX = 510000;
bool graph[nmax][nmax];
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;

    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}
ll A, B;

bool isOK(ll key)
{
    ll cnt = 0;
    for (int i = A; i <= B; i++)
    {
        if (i % key == 0)
        {
            cnt++;
        }
    }
    if (cnt >= 2)
    {
        return true;
    }
    else
    {
        return false;
    }
}

int main()
{
    scanf("%lld", &A);
    scanf("%lld", &B);
    ll ans = -1;
    for (int i = 1; i < 200010; i++)
    {
        ll mi = ceil(A, i);
        ll div = mi * i;
        ll div2 = (mi +1) * i;

        if (A <= div && div2 <= B)
        {
            ans = i;
        }
    }
    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=3010;
const int INF=1e9;
int n,a[maxn][5];
int dp[maxn][32][5];
bool solve(int mid) {
	memset(dp,0,sizeof(dp));
	dp[0][0][0]=1;
	for (int id=1;id<=n;id++) {
		int now=0;
		for (int i=0;i<=4;i++) if (a[id][i]>=mid) now|=(1<<i);
		for (int i=0;i<=3;i++) {
			for (int t=0;t<32;t++) if (dp[id-1][t][i]) {
				dp[id][t|now][i+1]=dp[id][t][i]=1;
			}
		}
	}
	return dp[n][31][3];
	
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++)
	for (int j=0;j<=4;j++) read(a[i][j]);
	int l=0,r=INF+10,res,mid;
	while (l<=r) {
		mid=(l+r)>>1;
		if (solve(mid)) res=mid,l=mid+1;
		else r=mid-1;
	}
	printf("%d\n",res);
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/