#include <bits/stdc++.h>
using namespace std;
int fastio() { ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); cin.tie(nullptr); return 0; }
int __fastio = fastio();

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
typedef long long ll;
typedef pair<ll, ll> ii;
#define fi first
#define se second
#define sz(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

int main(){
    string s;
    cin >> s;
    while(s.size() && s.back() == '0') s.pop_back();
    int lo = 0, hi = s.size()-1;
    while(lo<hi) {
        if(s[lo++] != s[hi--]) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i,s,n) for(int i = s; i < (int)(n); i++)
#define Rep(i,s,n) for(int i = n; i >= (int)(s); i--)

int n, x[3030][5];

int getmask(int i, int lim) {
	int res = 0;
	rep(j, 0, 5) if (lim <= x[i][j]) res += 1 << j;
	return res;
}

bool check(int lim) {
	vector<int>cnt(1 << 5, 0);
	rep(i, 0, n) cnt[getmask(i, lim)]++;
	rep(m1, 0, 1 << 5) rep(m2, 0, 1 << 5) rep(m3, 0, 1 << 5) {
		if ((m1 | m2 | m3) == (1 << 5) - 1 && cnt[m1] && cnt[m2] && cnt[m3]) return 1;
	}
	return 0;
}

int main() {
	cin >> n;
	rep(i, 0, n) rep(j, 0, 5) cin >> x[i][j];
	int ok = 0, ng = 1e9 + 1;
	while (ng - ok != 1) {
		int mid = (ok + ng) / 2;
		if (check(mid)) ok = mid;
		else ng = mid;
	}
	cout << ok << endl;
}