#include <iostream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

#define FOR(i,n,m) for(int i=n; i<(int)m; i++)
#define ROF(i,n,m) for(int i=n; i>(int)m; i--)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define ri(a) scanf("%d",&a)
#define rii(a,b) ri(a),ri(b)
#define riii(a,b,c) rii(a,b),ri(c)
#define lri(a) scanf("%lld",&a)
#define lrii(a,b) lri(a),lri(b)
#define ms(obj,val) memset(obj,val,sizeof(obj))
#define all(x) x.begin(),x.end()
#define debug true
#define dprintf debug && printf

const int INF = 0x3f3f3f3f;
const ll INFLL = 1e18;
const int MOD = 1e9+7;
const int MAXN = 2e5+5;

vii G[MAXN];
int col[MAXN];
int n, m;

void dfs(int v, int p = -1, int pc = -1){
    if(col[v]) return;
    if(p == -1) col[v] = 1; 
    else if(col[p] != pc) col[v] = pc;
    else col[v] = (pc == n ? 1 : pc + 1);
    for(auto up : G[v]){
        int u = up.F, uc = up.S;
        dfs(u, v, uc);
    }
}

int main(){
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);

    rii(n,m);
    FOR(i,0,m){
        int u, v, c;
        riii(u, v, c); u--, v--;
        G[u].pb({v, c});
        G[v].pb({u, c});
    }

    dfs(0);

    FOR(i,0,n) printf("%d\n", col[i]);

    return 0;
}

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

bool coprime(ll a, ll b) { 
      
    if ( __gcd(a, b) == 1) 
        return true;
    else
        return false;      
}

int main()
{
    ll N;
    cin >> N;
    ll X[N];

    for (ll i = 0; i < N; i++) {
        cin >> X[i];
    }

    const int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
 
	ll result = 1e18;

	for(int bit = 0; bit < (1 << 15); bit++) {
		ll p = 1;
		for(int i = 0; i < 15; i++) {
			if(bit & (1 << i)) p *= primes[i];
		}

        bool e = false;
		for (auto x : X) {
            if(coprime(x, p)) {
                e = true;
                break;
            }
        }

        if (e) {
            continue;
        }

        result = min(p, result);
	}
 
    cout << result << endl;
    
}
