#include <bits/stdc++.h>
typedef int_fast64_t lli;
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    lli n, m;
    cin >> n >> m;
    vector<pair<lli, lli>> a(m);
    vector<lli> vis(n, 0);
    for(lli i = 0, f, s; i < m; i++)
    {
        cin >> f >> s, f--, s--;
        a[i].first = f, a[i].second = s;

    }
    function<void(lli)> dfs = [&](lli cur)
    {
        if(vis[cur]) return;
        vis[cur] = 1;
        for(auto& x : a)
            if(x.first == cur) dfs(x.second);
    };
    dfs(0);
    for(auto& x : vis) if(!x) cout << "NO\n";
}
