#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, m;
vector<int> p[200001];
int low[200001], num[200001], dele[200001], lead[200001], cc = 0, scc = 0, lc[200001], tplt = 0, db[200001];
stack<int> st;
void nhap() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int a, b;
cin >> a >> b;
p[a].push_back(b);
}
}
void dfs(int u) {
low[u] = num[u] = ++cc;
st.push(u);
for (int v : p[u]) {
if (dele[v]) continue;
if (!num[v]) {
dfs(v);
low[u] = min(low[u], low[v]);
} else
low[u] = min(low[u], num[v]);
}
if (num[u] == low[u]) {
scc++;
lead[scc] = u;
while (true) {
int v = st.top();
st.pop();
dele[v] = scc;
if (v == u) break;
}
}
}
signed main() {
nhap();
for (int i = 1; i <= n; i++) {
if (!num[i]) {
tplt++;
db[tplt] = i;
dfs(i);
}
}
for (int i = 1; i <= n; i++) {
for (int v : p[i]) {
if (dele[v] != dele[i]) {
lc[dele[v]]++;
}
}
}
int ans = 0;
for (int i = 1; i <= scc; i++) {
if (lc[i] != 0) ans++;
}
if (tplt >= 2) {
cout << "NO" << "\n";
cout << db[1] << " " << db[2];
}
else
{
if (ans == 0)
cout << "YES";
else if (ans > 0) {
cout << "NO" << "\n";
int c = 0, d = 0;
for (int i = 1; i <= scc; i++) {
if (lc[i] != 0 && c == 0) {
cout << lead[i] << " ";
c = 1;
}
if (lc[i] == 0 && d == 0) {
cout << lead[i] << " ";
d = 1;
}
}
}
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBpbnQgbG9uZyBsb25nCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbiwgbTsKdmVjdG9yPGludD4gcFsyMDAwMDFdOwppbnQgbG93WzIwMDAwMV0sIG51bVsyMDAwMDFdLCBkZWxlWzIwMDAwMV0sIGxlYWRbMjAwMDAxXSwgY2MgPSAwLCBzY2MgPSAwLCBsY1syMDAwMDFdLCB0cGx0ID0gMCwgZGJbMjAwMDAxXTsKc3RhY2s8aW50PiBzdDsKCnZvaWQgbmhhcCgpIHsKICAgIGNpbiA+PiBuID4+IG07CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBtOyBpKyspIHsKICAgICAgICBpbnQgYSwgYjsKICAgICAgICBjaW4gPj4gYSA+PiBiOwogICAgICAgIHBbYV0ucHVzaF9iYWNrKGIpOwogICAgfQp9Cgp2b2lkIGRmcyhpbnQgdSkgewogICAgbG93W3VdID0gbnVtW3VdID0gKytjYzsKICAgIHN0LnB1c2godSk7CiAgICBmb3IgKGludCB2IDogcFt1XSkgewogICAgICAgIGlmIChkZWxlW3ZdKSBjb250aW51ZTsKICAgICAgICBpZiAoIW51bVt2XSkgewogICAgICAgICAgICBkZnModik7CiAgICAgICAgICAgIGxvd1t1XSA9IG1pbihsb3dbdV0sIGxvd1t2XSk7CiAgICAgICAgfSBlbHNlCiAgICAgICAgICAgIGxvd1t1XSA9IG1pbihsb3dbdV0sIG51bVt2XSk7CiAgICB9CiAgICBpZiAobnVtW3VdID09IGxvd1t1XSkgewogICAgICAgIHNjYysrOwogICAgICAgIGxlYWRbc2NjXSA9IHU7CiAgICAgICAgd2hpbGUgKHRydWUpIHsKICAgICAgICAgICAgaW50IHYgPSBzdC50b3AoKTsKICAgICAgICAgICAgc3QucG9wKCk7CiAgICAgICAgICAgIGRlbGVbdl0gPSBzY2M7CiAgICAgICAgICAgIGlmICh2ID09IHUpIGJyZWFrOwogICAgICAgIH0KICAgIH0KfQoKc2lnbmVkIG1haW4oKSB7CiAgICBuaGFwKCk7CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpKyspIHsKICAgICAgICBpZiAoIW51bVtpXSkgewogICAgICAgICAgICB0cGx0Kys7CiAgICAgICAgICAgIGRiW3RwbHRdID0gaTsKICAgICAgICAgICAgZGZzKGkpOwogICAgICAgIH0KICAgIH0KICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkrKykgewogICAgICAgIGZvciAoaW50IHYgOiBwW2ldKSB7CiAgICAgICAgICAgIGlmIChkZWxlW3ZdICE9IGRlbGVbaV0pIHsKICAgICAgICAgICAgICAgIGxjW2RlbGVbdl1dKys7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICBpbnQgYW5zID0gMDsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IHNjYzsgaSsrKSB7CiAgICAgICAgaWYgKGxjW2ldICE9IDApIGFucysrOwogICAgfQogICAgaWYgKHRwbHQgPj0gMikgewogICAgICAgIGNvdXQgPDwgIk5PIiA8PCAiXG4iOwogICAgICAgIGNvdXQgPDwgZGJbMV0gPDwgIiAiIDw8IGRiWzJdOwogICAgfQogICAgZWxzZQogICAgewogICAgICAgIGlmIChhbnMgPT0gMCkKICAgICAgICBjb3V0IDw8ICJZRVMiOwogICAgICAgIGVsc2UgaWYgKGFucyA+IDApIHsKICAgICAgICBjb3V0IDw8ICJOTyIgPDwgIlxuIjsKICAgICAgICBpbnQgYyA9IDAsIGQgPSAwOwogICAgICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IHNjYzsgaSsrKSB7CiAgICAgICAgICAgIGlmIChsY1tpXSAhPSAwICYmIGMgPT0gMCkgewogICAgICAgICAgICAgICAgY291dCA8PCBsZWFkW2ldIDw8ICIgIjsKICAgICAgICAgICAgICAgIGMgPSAxOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChsY1tpXSA9PSAwICYmIGQgPT0gMCkgewogICAgICAgICAgICAgICAgY291dCA8PCBsZWFkW2ldIDw8ICIgIjsKICAgICAgICAgICAgICAgIGQgPSAxOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgfQp9Cg==