#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
double pi=acos(-1);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
// #define mp make_pair
#define pq priority_queue
const ll mod=1000000007;
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

// using namespace boost::multiprecision;
using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


const int N=1000005;
ll fact[N],invfact[N];
ll power(ll x,ll y){
  if(y<=0) return 1LL;
  ll z=power(x,y/2);
  if(y%2) return (((z*z)%mod)*x)%mod;
  return (z*z)%mod;
}

void pre(){
  fact[0]=invfact[0]=invfact[1]=fact[1]=1;
  rep(i,2,N) fact[i]=(i*fact[i-1])%mod;
  rep(i,2,N) invfact[i]=(invfact[i-1]*power(i,mod-2))%mod;
}
ll nCr(ll n,ll k){ return (((fact[n]*invfact[n-k])%mod)*invfact[k])%mod; }



const int N1=1e6+1;
vector<int> isprime(N1,1),prime;
void seive(){
  rep(i,2,sqrt(N1)+1){
      if(isprime[i]){
        for(int j=i*i;j<N1;j+=i) isprime[j]=0;
        prime.pb(i);
      }
  }
  rep(i,sqrt(N1)+1,N1) if(isprime[i]) prime.pb(i);
}



struct dsu {
    vector<int> par, rank;
    dsu(int n): par(n+1), rank(n+1) {
        for (int i = 0; i <= n; i++) {
            par[i] = i;
            rank[i]= 1;
        }
    }
    int root(int a) {
        if (a == par[a]) return a;
        return par[a] = root(par[a]);
    }
    void merge(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) return;
        if (rank[a] > rank[b]) swap(a, b);
        par[b] = a;
    }
    set<int> parent(int n){
        set<int> s;
        for(int i=1;i<=n;i++){
            s.insert(root(i));
        }
        return s;
    }
};

void solve(){
  int n;
  cin>>n;
  int a[n],b[n];
  rep(i,0,n){cin>>a[i]; b[i]=0;}
  rep(i,0,n) b[a[i]-1]++;
  int flag=0;
  rep(i,0,n){
    if(b[i]==0 || b[i]>1) flag=1;
  }
  if(flag) cout<<"No";
  else cout<<"Yes";
}

int main(){
    optimizeIO();
    int r=1;
    {solve();}
}

#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(register int i=(a);i<=(b);i++)
#define per(i,a,b) for(register int i=(a);i>=(b);i--)
using namespace std;
const int N=2009,inf=0x3f3f3f3f3f3f3f3f;

inline int read() {
    register int x=0, f=1; register char c=getchar();
    while(c<'0'||c>'9') {if(c=='-') f=-1; c=getchar();}
    while(c>='0'&&c<='9') {x=(x<<3)+(x<<1)+c-48,c=getchar();}
    return x*f;
}

int n,m,a[N],b[N],c[N],d[N];
bool vst[N];
struct edge {int to,w;};
vector<edge>e[N];
struct node {
	int u,w;
	bool operator < (const node &b) const {
		return w>b.w;
	}
};
void dijakstra(int s) {
	priority_queue<node>q; q.push((node){s,0});
	memset(d,0x3f,sizeof(d)); d[s]=0;
	memset(vst,0,sizeof(vst));
	while(!q.empty()) {
		int u=q.top().u; q.pop();
		if(vst[u]) continue; vst[u]=1;
		for(auto ed:e[u])
			if(d[ed.to]>d[u]+ed.w)
				d[ed.to]=d[u]+ed.w, q.push((node){ed.to,d[ed.to]});
	}
}

signed main() {
	n=read(), m=read();
	rep(i,1,m) a[i]=read(), b[i]=read(), c[i]=read();
	rep(i,1,n) {
		rep(j,1,n) e[j].clear();
		rep(j,1,m) {
			if(b[j]==i) e[a[j]].push_back((edge){n+1,c[j]});
			else e[a[j]].push_back((edge){b[j],c[j]});
		}
		dijakstra(i);
		printf("%lld\n",d[n+1]<inf?d[n+1]:-1ll);
	}
	return 0;
}