#include<bits/stdc++.h>
using namespace std;
#define int long long
#define loop(i, start, end) for (int i = start; i <= end; i++)
#define rloop(i, start, end) for (int i = start; i >= end; i--)
#define vi vector<int>
#define vec(x) vector<x>
#define sz(v) (int)v.size() 
#define UB upper_bound
#define LB lower_bound
#define all(v) (v).begin(),(v).end()
#define arl(v) (v).rbegin(),(v).rend()
#define fsp(a) fixed<<setprecision(a)
#define mem(a,with) memset(a, with, sizeof (a))
#define vmn(a) (*min_element(a.begin(),a.end()))   
#define vmx(a) (*max_element(a.begin(),a.end()))
#define bs(a,key) binary_search(all(a),key)    /// return bool.
#define rotl(a,x) rotate(a.begin(),a.begin()+x,a.end());
#define rotr(a,x) rotl(a,a.size()-x);
#define nl cout<<endl
#define MOD 1000000007
int add(int x, int y) {int res = x + y; return (res >= MOD ? res - MOD : res);}
int mul(int x, int y) {int res = x * y; return (res >= MOD ? res % MOD : res);}
int power(int x, int y) {int res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}

void solve(){
    //code goes here
    int n;
    cin>>n;
    int arr[n];
    loop(i,0,n-1) cin>>arr[i];

    int num=0,mx=0;
    loop(i,2,1000){
        int cnt=0;
        loop(j,0,n-1){
            if(arr[j]%i==0){
                cnt++;
            }
        }
        if(cnt>mx){
            mx=cnt;
            num=i;
        }
    }

    cout<<num;
}

int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
    int t=1;
    // cin>>t;
    while (t--)
    {
        solve();
    }
    return 0;
}
#include <iostream> 
#include <cstdio>
#include <string>
#include <sstream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <iterator>
#include <algorithm>
#include <cmath>
#include <chrono>
#include <cassert>

using namespace std;
using ll = long long;
using ld = long double;
using ii = pair<ll, ll>;
using vi = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vvii = vector<vii>;

const int INF = 2000000000;
const ll LLINF = 9000000000000000000;

int main() {
	
	int N;
	scanf("%d", &N);
	
	vvii E(N, vii());
	
	ll m;
	cin >> m;
	ll a, b, c;
	vector<pair<pair<ll, ll>, ll>> edges;
	for (int i = 0; i < m; ++i) {
	    cin >> a >> b >> c;
	    --a, --b;
	    E[a].push_back({b, c});
	    edges.push_back({{a, b}, c});
	}
	vi ans(N, -1LL);
	
	for (auto p : edges) {
		vi d(N, LLINF);
		priority_queue<ii, vector<ii>, greater<ii>> pq;
		int u = p.first.second;
		
		pq.push({0LL, u});
		d[u] = 0LL;
		
		vi pdd(N, -1LL);
		while (!pq.empty()) {
			ll v = pq.top().second;
			ll dist = pq.top().first;
			pq.pop();
			
			if (dist > d[v]) continue;
			for (ii wd : E[v]) {
			    if (p.first.first == v && p.first.second == wd.first && p.second == wd.second) continue;
				ll w = wd.first;
				ll dist2 = wd.second;
				if (dist + dist2 < d[w]) {
					d[w] = dist + dist2;
					pdd[w] = v;
					pq.push({d[w], w});
				}
			} 
		}
		if (d[p.first.first] == LLINF) continue;
		
		if (ans[p.first.first] == -1) {
		    ans[p.first.first] = d[p.first.first] + p.second;
		}else {
		    ans[p.first.first] = min(ans[p.first.first], d[p.first.first] + p.second);
		}
		if (ans[p.first.second] == -1) {
		    ans[p.first.second] = d[p.first.first] + p.second;
		}else {
		    ans[p.first.second] = min(ans[p.first.second], d[p.first.first] + p.second);
		}
		
	}
	
	for (int i = 0; i < N; ++i)
		cout << ans[i] << '\n';
	
	return 0;
}
