#include <bits/stdc++.h>
using namespace std;
//variable
#define ld long double
#define ll long long
#define db double
#define ii pair<int,int>
#define f first
#define s second
#define mp make_pair
#define mt make_tuple
//vector
#define pb push_back
#define all(v) v.begin(),v.end()
#define len(a) (int)a.length()
#define sz(a) (int)a.size()
//mask
#define BIT(i) (1LL<<(i))
//better code, debugger
#define watch(n) cerr << #n << ": " << n << endl
#define debug(x) for (auto p: x) cerr<<p<<' ';cerr<<endl
#define forw(i,j,z) for(int i=(int)j;i<=(int)z;i++)
#define ford(i,j,z) for (int i=(int)j;i>=(int)z;i--)
#define fIlE "."
//auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
//mt19937 RAND(seed);
const int mod = 998244353;
inline int add(int u,int v){u+=v;if(u>=mod)u-=mod;return u;}
inline int dec(int u,int v){u-=v;if(u<0)u+=mod;return u;}
inline int mul(int u,int v){return (ll)u*v%mod;}
const ii inf = mp(-1, -1);
ii ans = inf;
const int N = 1e5 + 1;
int num[N], low[N];
vector<int> a[N];
int timedfs = 0, timedfs2 = 0;
int n, m;
stack<int> haha;
int id[N];
bool del[N];
void dfs(int u)
{
num[u] = low[u] = ++timedfs;
haha.push(u);
for (int v : a[u]){
if (del[v]) continue;
if (!num[v]){
dfs(v);
low[u] = min(low[u], low[v]);
}
else low[u] = min(low[u], num[v]);
}
if (low[u] >= num[u])
{
int id_group = ++timedfs2;
while(!haha.empty() && low[u] >= num[u])
{
int v = haha.top();
del[v] = 1;
haha.pop();
id[v] = id_group;
if (v == u) break;
}
}
}
void solve()
{
cin >> n >> m;
forw(i, 1, m){
int u, v;
cin >> u >> v;
if (u == v) continue;
a[u].pb(v);
}
forw(i, 1, n) if (!num[i])
dfs(i);
if (timedfs2 > 1){
int u = 1;
forw(v, 2, n) if (id[u] != id[v]){
if (id[u] < id[v]) swap(u, v);
cout << "NO\n";
cout << v << ' ' << u;
return;
}
}
else cout << "YES";
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen(fIlE"inp", "r"))
freopen(fIlE"inp","r",stdin), freopen(fIlE"out","w",stdout);
//time_t TIME_TU=clock();
int t=1;
// cin>>t;
while(t--)
solve();
//time_t TIME_TV=clock();
//cerr<<(db)(TIME_TV-TIME_TU)/CLOCKS_PER_SEC<<endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Ci8vdmFyaWFibGUKI2RlZmluZSBsZCBsb25nIGRvdWJsZQojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIGRiIGRvdWJsZQojZGVmaW5lIGlpIHBhaXI8aW50LGludD4KI2RlZmluZSBmIGZpcnN0CiNkZWZpbmUgcyBzZWNvbmQKI2RlZmluZSBtcCBtYWtlX3BhaXIKI2RlZmluZSBtdCBtYWtlX3R1cGxlCi8vdmVjdG9yCiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgYWxsKHYpIHYuYmVnaW4oKSx2LmVuZCgpCiNkZWZpbmUgbGVuKGEpIChpbnQpYS5sZW5ndGgoKQojZGVmaW5lIHN6KGEpIChpbnQpYS5zaXplKCkKLy9tYXNrCiNkZWZpbmUgQklUKGkpICgxTEw8PChpKSkKLy9iZXR0ZXIgY29kZSwgZGVidWdnZXIKI2RlZmluZSB3YXRjaChuKSBjZXJyIDw8ICNuIDw8ICI6ICIgPDwgbiA8PCBlbmRsCiNkZWZpbmUgZGVidWcoeCkgZm9yIChhdXRvIHA6IHgpIGNlcnI8PHA8PCcgJztjZXJyPDxlbmRsCiNkZWZpbmUgZm9ydyhpLGoseikgZm9yKGludCBpPShpbnQpajtpPD0oaW50KXo7aSsrKQojZGVmaW5lIGZvcmQoaSxqLHopIGZvciAoaW50IGk9KGludClqO2k+PShpbnQpejtpLS0pCiNkZWZpbmUgZklsRSAiLiIKLy9hdXRvIHNlZWQgPSBjaHJvbm86OmhpZ2hfcmVzb2x1dGlvbl9jbG9jazo6bm93KCkudGltZV9zaW5jZV9lcG9jaCgpLmNvdW50KCk7Ci8vbXQxOTkzNyBSQU5EKHNlZWQpOwpjb25zdCBpbnQgbW9kID0gOTk4MjQ0MzUzOwppbmxpbmUgaW50IGFkZChpbnQgdSxpbnQgdil7dSs9djtpZih1Pj1tb2QpdS09bW9kO3JldHVybiB1O30KaW5saW5lIGludCBkZWMoaW50IHUsaW50IHYpe3UtPXY7aWYodTwwKXUrPW1vZDtyZXR1cm4gdTt9CmlubGluZSBpbnQgbXVsKGludCB1LGludCB2KXtyZXR1cm4gKGxsKXUqdiVtb2Q7fQpjb25zdCBpaSBpbmYgPSBtcCgtMSwgLTEpOwppaSBhbnMgPSBpbmY7CmNvbnN0IGludCBOID0gMWU1ICsgMTsKaW50IG51bVtOXSwgbG93W05dOwp2ZWN0b3I8aW50PiBhW05dOwppbnQgdGltZWRmcyA9IDAsIHRpbWVkZnMyID0gMDsKaW50IG4sIG07CnN0YWNrPGludD4gaGFoYTsKaW50IGlkW05dOwpib29sIGRlbFtOXTsKCnZvaWQgZGZzKGludCB1KQp7CiAgICBudW1bdV0gPSBsb3dbdV0gPSArK3RpbWVkZnM7CiAgICBoYWhhLnB1c2godSk7CiAgICBmb3IgKGludCB2IDogYVt1XSl7CiAgICAgICAgaWYgKGRlbFt2XSkgY29udGludWU7CiAgICAgICAgaWYgKCFudW1bdl0pewogICAgICAgICAgICBkZnModik7CiAgICAgICAgICAgIGxvd1t1XSA9IG1pbihsb3dbdV0sIGxvd1t2XSk7CiAgICAgICAgfQogICAgICAgIGVsc2UgbG93W3VdID0gbWluKGxvd1t1XSwgbnVtW3ZdKTsKICAgIH0KICAgIGlmIChsb3dbdV0gPj0gbnVtW3VdKQogICAgewogICAgICAgIGludCBpZF9ncm91cCA9ICsrdGltZWRmczI7CiAgICAgICAgd2hpbGUoIWhhaGEuZW1wdHkoKSAmJiBsb3dbdV0gPj0gbnVtW3VdKQogICAgICAgIHsKICAgICAgICAgICAgaW50IHYgPSBoYWhhLnRvcCgpOwogICAgICAgICAgICBkZWxbdl0gPSAxOwogICAgICAgICAgICBoYWhhLnBvcCgpOwogICAgICAgICAgICBpZFt2XSA9IGlkX2dyb3VwOwogICAgICAgICAgICBpZiAodiA9PSB1KSBicmVhazsKICAgICAgICB9CiAgICB9Cn0Kdm9pZCBzb2x2ZSgpCnsKICAgIGNpbiA+PiBuID4+IG07CiAgICBmb3J3KGksIDEsIG0pewogICAgICAgIGludCB1LCB2OwogICAgICAgIGNpbiA+PiB1ID4+IHY7CiAgICAgICAgaWYgKHUgPT0gdikgY29udGludWU7CiAgICAgICAgYVt1XS5wYih2KTsKICAgIH0KICAgIGZvcncoaSwgMSwgbikgaWYgKCFudW1baV0pCiAgICAgICAgZGZzKGkpOwogICAgaWYgKHRpbWVkZnMyID4gMSl7CiAgICAgICAgaW50IHUgPSAxOwogICAgICAgIGZvcncodiwgMiwgbikgaWYgKGlkW3VdICE9IGlkW3ZdKXsKICAgICAgICAgICAgaWYgKGlkW3VdIDwgaWRbdl0pIHN3YXAodSwgdik7CiAgICAgICAgICAgIGNvdXQgPDwgIk5PXG4iOwogICAgICAgICAgICBjb3V0IDw8IHYgPDwgJyAnIDw8IHU7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICB9CiAgICBlbHNlIGNvdXQgPDwgIllFUyI7Cn0Kc2lnbmVkIG1haW4oKQp7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgIGNpbi50aWUoMCk7CiAgICBpZiAoZm9wZW4oZklsRSJpbnAiLCAiciIpKQogICAgICAgIGZyZW9wZW4oZklsRSJpbnAiLCJyIixzdGRpbiksIGZyZW9wZW4oZklsRSJvdXQiLCJ3IixzdGRvdXQpOwogICAgLy90aW1lX3QgVElNRV9UVT1jbG9jaygpOwogICAgaW50IHQ9MTsKLy8gICAgY2luPj50OwogICAgd2hpbGUodC0tKQogICAgICAgIHNvbHZlKCk7CiAgICAvL3RpbWVfdCBUSU1FX1RWPWNsb2NrKCk7CiAgICAvL2NlcnI8PChkYikoVElNRV9UVi1USU1FX1RVKS9DTE9DS1NfUEVSX1NFQzw8ZW5kbDsKICAgIHJldHVybiAwOwp9Cg==