#include <bits/stdc++.h>
using namespace std;
#define NMAX 10005
#define MMAX 100005
int euclid(int a, int b) {
if(!b)
return a;
return euclid(b, a%b);
}
int cmmmc(int a, int b) {
return a*b/euclid(a, b);
}
struct myType {
int i, j, d;
};
vector<myType> date;
int main()
{
freopen("oz.in", "r", stdin);
freopen("oz.out", "w", stdout);
vector<int> sir(NMAX, 1);
int n, m;
scanf("%d%d", &n, &m);
for(int k = 1; k <= m; ++k) {
myType temp;
scanf("%d%d%d", &temp.i, &temp.j, &temp.d);
sir[temp.i] = cmmmc(sir[temp.i], temp.d);
sir[temp.j] = cmmmc(sir[temp.j], temp.d);
date.push_back(temp);
}
for(auto it = date.begin(); it != date.end(); ++it) {
if(euclid(sir[(*it).i], sir[(*it).j]) != (*it).d) {
printf("-1");
return 0;
}
}
for(int i = 1; i <= n; ++i)
printf("%d ", sir[i]);
return 0;
}