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

int n;
vector <int> g[105000];
bool vis[105000];
map <int, int> way;
bool findd = 0;

void dfs(int v, int cnt) {
    vis[v] = 1;
    cnt++;
    way[v] = cnt;
    for (auto i : g[v]) {
        if (!vis[i])
            dfs(i, cnt + 1);
        if (i == 1 && cnt == n) {
            findd = 1;
            return;
        }
    }
}

int main() {
    int m;
    cin >> n >> m;
    if (m < n) {
        cout << "NO";
        return 0;
    }
    for (int i = 0; i < m; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        g[a].push_back(b);
    }
    dfs(1, 0);
    if (!findd) {
        cout << "NO";
        return 0;
    }
    vector <pair <int, int> > get_way;
    for (auto i : way) {
        get_way.push_back({i.second, i.first});
    }
    sort(get_way.begin(), get_way.end());
    for (auto i : get_way)
        cout << i.first;
    return 0;
}
