#include<stdio.h>
#include <iostream>
#include<cmath>
#include <cctype>
#include <cstdlib>
#include<cstring>
#include<algorithm>
#include <vector>
#include<queue>

using namespace std;
#define ll long long
#define il inline
#define oo (2147000000)
#define sc(x) scanf("%d",&x)
#define scc(x, y) scanf("%d%d",&x,&y)
#define sccc(x, y, z) scanf("%d%d%d",&x,&y,&z)
#define p(x) printf("%d\n",x)
#define m(x, y) ((x+y)>>1)
#define l(x) (x<<1)
#define r(x) (x<<1|1)
const int maxn = 1e5 + 6;


int main() {
    int m, n, i, j, k;
    //u、v、w和next的数组大小要根据实际情况来设置,要比m的最大值要大1,若是双向图,则为2*m+1
    int u[6], v[6], w[6], next[6];
    //first的数组大小要根据实际情况来设置,要比n的最大值要大1
    int first[5];//存储每个顶点其中一条边的编号

    scc(n, m);
    for (i = 1; i <= n; i++)
        first[i] = -1;
    for (i = 1; i <= m; i++) {//读入m条边
        sccc(u[i], v[i], w[i]);
        next[i] = first[u[i]];
        first[u[i]] = i;
    }

    //找出与n点相连的边,k=first[n],这里n=1
    k = first[1];
    while (k!=-1){
        printf("%d%d%d",u[k],v[k],w[k]);
        k=next[k];
    }
}

hhhhh