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

const int N = 2005;
const int oo = 0x3f3f3f3f;

int Gcd(int a, int b) {
	return (b ? Gcd(b, a % b) : a);
}

int a[N], ans = 0, mn, f = 1;

map<int,int> mp;

void get(int a, int b) {

	if (!mp.count(a)) {
		mp[a] = b;
		return;
	}

	if (mp[a] == a) return;

	int x = mp[a];

	x = Gcd(x, b);

	if (x == a) {
		ans++;
		if (a == mn) f = 0;
		// cout << a << '\n';
	}

	mp[a] = x;

}

void solve(){
	int n;
	cin >> n;

	mn = oo;

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

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j * j <= a[i]; j++) {
			if (a[i] % j == 0) {
				if (j <= mn)
				get(j, a[i]);
				if (j * j != a[i] && a[i] / j <= mn) 
					get(a[i] / j, a[i]);
			}
		}
	}		

	cout << ans + f;

}

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

	#ifdef local
	freopen("inp.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	
	solve();

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

using namespace std;

#define closeSync ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef long double ld;
const int MAXN = 3005;

typedef pair<ld,ld> pll;

ll a[MAXN][7];
int flag[MAXN];
int n;  

inline bool check(ll x)
{
    set<int> s;
    for (int i=1;i<=n;i++)
    {
        ll tmp = 0;
        for (int j=1;j<=5;j++)
        {
            if (a[i][j] >= x)
                tmp |= (1LL<<(j-1));
        }
        s.insert(tmp);
    }
    for (auto x : s)
        for (auto y : s)
            for (auto z : s)
            {
                // cout << x << " " << y << " " << z << "\n";
                if ((x|y|z) == 31)
                    return true;
            }   
    return false;
}

inline void solve()
{
    cin >> n;
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=5;j++)
        {
            cin >> a[i][j];
        }
    }

    ll l = 0,r = 1e10;
    // cout << check(4) << "\n";
    // cout << check(r) << endl;
    while (r - l > 1)
    {
        ll mid = (l + r) >> 1;
        if (check(mid))
            l = mid;
        else 
            r = mid;
    }
    
    if (check(r))
        cout << r << "\n";
    else 
        cout << l << "\n";

    return ;
}

int main()
{closeSync;
    // int T;  cin >> T;
    // while (T--)
        solve();
    return 0;
}

/*
aRbRcRd
*/