import java.io.*

private val env = HashSet<String>();
private lateinit var reader: BufferedReader;

fun main(args: Array<String>) {
    args.forEach { e -> run {
            env.add(e)
        } };
    beforeInvocation();
    run();
    afterInvocation();
}

fun ins(): InputStream {
    return if (env.contains("DEBUG")) FileInputStream("test.in");
    else System.`in`;
}

fun beforeInvocation() {
    reader = BufferedReader(InputStreamReader(ins()));
}

fun afterInvocation() {
}

fun run() {

    for (test in 0 until reader.readLine().toInt()) {
        var (n, k1, k2) = reader.readLine().split(" ").map { it.toInt() }
        var s = reader.readLine()
        var ans = 0.toLong()
        var len = 0
        for(i in s.indices){
            if(s[i] == '0'){
                ans += (len/2+len%2)*k1 + len/2*(k2-k1)
                len = 0
            }
            else{
                len++
            }
        }
        ans += (len/2+len%2)*k1 + len/2*(k2-k1)
        println("$ans")
    }

}


import java.io.*
import java.lang.Integer.min

private val env = HashSet<String>();
private lateinit var reader: BufferedReader;

fun main(args: Array<String>) {
    args.forEach { e -> run {
            env.add(e)
        } };
    beforeInvocation();
    run();
    afterInvocation();
}

fun ins(): InputStream {
    return if (env.contains("DEBUG")) FileInputStream("test.in");
    else System.`in`;
}

fun beforeInvocation() {
    reader = BufferedReader(InputStreamReader(ins()));
}

fun afterInvocation() {
}

fun run() {

    for (test in 0 until reader.readLine().toInt()) {
        var (n, k1, k2) = reader.readLine().split(" ").map { it.toInt() }
        var s = reader.readLine()
        var ans = 0.toLong()
        var len = 0
        for(i in s.indices){
            if(s[i] == '0'){
                ans += (len/2+len%2)*k1 + len/2*min(k2-k1, k1)
                len = 0
            }
            else{
                len++
            }
        }
        ans += (len/2+len%2)*k1 + len/2*min(k2-k1, k1)
        println("$ans")
    }

}


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader

fun main() {
    problemB(System.`in`)
}

fun problemB(inputStream: InputStream) {
    val time = System.nanoTime()
    val reader = BufferedReader(InputStreamReader(inputStream))
    val exampleCount = reader.readLine().toInt()
    for (i in 1..exampleCount) {
        val params = reader.readLine().split(" ").map { it.toInt() }
        val n = params[0]
        val k1 = params[1]
        val k2 = params[2]
        val dayOffs = reader.readLine().map { it.toString().toInt() }.toIntArray()
        solve(n, k1, k2, dayOffs)
    }
//    println("Performed in ${(System.nanoTime()-time)/10e6}ms")
}

fun solve(n: Int, k1: Int, k2: Int, dayOffs: IntArray) {
    val c = IntArray(n, { i -> k1 })

    var hasNext = true
    while (hasNext) {
//        println(Arrays.toString(c))
        val total = check(c, k2, dayOffs)
        if (total != null){
            println(total)
//        println(Arrays.toString(c))
        return
        }
        hasNext = next(c, k1, dayOffs)
    }
}

fun check(c: IntArray, k2: Int, dayOffs: IntArray): Int? {
    for (i in 0..c.size-2) {
        if ((c[i]+c[i+1])>k2) return null
        if (c[i]>0 && dayOffs[i]==0) return null
    }
    if (c[c.size-1]>0 && dayOffs[c.size-1]==0) return null
    return c.sum()
}

fun next(c: IntArray, maxPerDay: Int, dayOffs: IntArray): Boolean {
    var pos = 0
    while (c[pos] == 0) {
        c[pos] = if (dayOffs[pos] == 0) 0 else maxPerDay
        pos++
    }
    c[pos]--
    return c.any { it != 0 }
}


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader

fun main() {
    problemB(System.`in`)
}

fun problemB(inputStream: InputStream) {
    val time = System.nanoTime()
    val reader = BufferedReader(InputStreamReader(inputStream))
    val exampleCount = reader.readLine().toInt()
    for (i in 1..exampleCount) {
        val params = reader.readLine().split(" ").map { it.toInt() }
        val n = params[0]
        val k1 = params[1]
        val k2 = params[2]
        val dayOffs = reader.readLine().map { it.toString().toInt() }.toIntArray()
        solve(n, k1, k2, dayOffs)
    }
//    println("Performed in ${(System.nanoTime()-time)/10e6}ms")
}

fun solve(n: Int, k1: Int, k2: Int, dayOffs: IntArray) {
    val c = IntArray(n, { i -> k1 })

    var hasNext = true
    while (hasNext) {
//        println(Arrays.toString(c))
        val total = check(c, k2, dayOffs)
        if (total != null){
            println(total)
//        println(Arrays.toString(c))
        return
        }
        hasNext = next(c, k1, dayOffs, k2)
    }
}

fun check(c: IntArray, k2: Int, dayOffs: IntArray): Int? {
    for (i in 0..c.size-2) {
        if ((c[i]+c[i+1])>k2) return null
        if (c[i]>0 && dayOffs[i]==0) return null
    }
    if (c[c.size-1]>0 && dayOffs[c.size-1]==0) return null
    return c.sum()
}

fun next(c: IntArray, maxPerDay: Int, dayOffs: IntArray, k2: Int): Boolean {
    var pos = 0
    while (c[pos] == 0) {
        val cPrev = if (pos == 0) 0 else c[pos - 1]
        c[pos] = if (dayOffs[pos] == 0) 0 else minOf(k2-cPrev, maxPerDay)
        pos++
    }
    c[pos]--
    return c.any { it != 0 }
}


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader

fun main() {
    problemB(System.`in`)
}

fun problemB(inputStream: InputStream) {
    val time = System.nanoTime()
    val reader = BufferedReader(InputStreamReader(inputStream))
    val exampleCount = reader.readLine().toInt()
    for (i in 1..exampleCount) {
        val params = reader.readLine().split(" ").map { it.toInt() }
        val n = params[0]
        val k1 = params[1]
        val k2 = params[2]
        val s = reader.readLine()
        val dayOffs = s.map { if (it == '0') 0 else 1 }.toIntArray()
        solveFast(n, k1, k2, dayOffs)
    }
//    println("Performed in ${(System.nanoTime()-time)/10e6}ms")
}

fun solveFast(n: Int, k1: Int, k2: Int, dayOffs: IntArray) {
    var workInARow = 0
    var result = 0
    for ((i, d) in dayOffs.withIndex()) {
        if (d == 0) workInARow=0 else workInARow++
        val thisDayCount = if (d==0) 0
        else {
            if ((i < n - 1 && dayOffs[i + 1] == 0) || i == (n - 1)) k1
        else {
            if ((workInARow % 2) == 1) minOf(k2 - k1, k1) else k1
        }
        }
        result+=thisDayCount
    }
    println(result)
}


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader

fun main() {
    problemB(System.`in`)
}

fun problemB(inputStream: InputStream) {
    val time = System.nanoTime()
    val reader = BufferedReader(InputStreamReader(inputStream))
    val exampleCount = reader.readLine().toInt()
    for (i in 1..exampleCount) {
        val params = reader.readLine().split(" ").map { it.toInt() }
        val n = params[0]
        val k1 = params[1]
        val k2 = params[2]
        val dayOffs = reader.readLine().map { it.toString().toInt() }.toIntArray()
        solve(n, k1, k2, dayOffs)
    }
//    println("Performed in ${(System.nanoTime()-time)/10e6}ms")
}

fun solve(n: Int, k1: Int, k2: Int, dayOffs: IntArray) {
    val c = IntArray(n) { i -> if (dayOffs[i] == 0) 0 else k1 }

    var hasNext = true
    while (hasNext) {
//        println(Arrays.toString(c))
        val total = check(c, k2, dayOffs)
        if (total != null){
            println(total)
//        println(Arrays.toString(c))
        return
        }
        hasNext = next(c, k1, dayOffs, k2)
    }
}

fun check(c: IntArray, k2: Int, dayOffs: IntArray): Int? {
    for (i in 0..c.size-2) {
        if ((c[i]+c[i+1])>k2) return null
        if (c[i]>0 && dayOffs[i]==0) return null
    }
    if (c[c.size-1]>0 && dayOffs[c.size-1]==0) return null
    return c.sum()
}

fun next(c: IntArray, maxPerDay: Int, dayOffs: IntArray, k2: Int): Boolean {
    var pos = 0
    while (c[pos] == 0) {
        val cPrev = if (pos == 0) 0 else c[pos - 1]
        c[pos] = if (dayOffs[pos] == 0) 0 else minOf(k2-cPrev, maxPerDay)
        pos++
    }
    c[pos]--
    return c.any { it != 0 }
}


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader

fun main() {
    problemB(System.`in`)
}

fun problemB(inputStream: InputStream) {
    val time = System.nanoTime()
    val reader = BufferedReader(InputStreamReader(inputStream))
    val exampleCount = reader.readLine().toInt()
    for (i in 1..exampleCount) {
        val params = reader.readLine().split(" ").map { it.toInt() }
        val n = params[0]
        val k1 = params[1]
        val k2 = params[2]
        val s = reader.readLine()
        val dayOffs = s.map { if (it == '0') 0 else 1 }.toIntArray()
        solve(n, k1, k2, dayOffs)
    }
//    println("Performed in ${(System.nanoTime()-time)/10e6}ms")
}

fun solve(n: Int, k1: Int, k2: Int, dayOffs: IntArray) {
    val c = IntArray(n) { i -> if (dayOffs[i] == 0) 0 else k1 }

    var hasNext = true
    while (hasNext) {
//        println(Arrays.toString(c))
        val total = check(c, k2, dayOffs)
        if (total != null){
            println(total)
//        println(Arrays.toString(c))
        return
        }
        hasNext = next(c, k1, dayOffs, k2)
    }
}

fun check(c: IntArray, k2: Int, dayOffs: IntArray): Int? {
    for (i in 0..c.size-2) {
        if ((c[i]+c[i+1])>k2) return null
        if (c[i]>0 && dayOffs[i]==0) return null
    }
    if (c[c.size-1]>0 && dayOffs[c.size-1]==0) return null
    return c.sum()
}

fun next(c: IntArray, maxPerDay: Int, dayOffs: IntArray, k2: Int): Boolean {
    var pos = 0
    while (c[pos] == 0) {
        val cPrev = if (pos == 0) 0 else c[pos - 1]
        val cNext = if (pos == c.size-1) 0 else c[pos + 1]
        c[pos] = if (dayOffs[pos] == 0) 0 else minOf(k2-cPrev, k2-cNext+1, maxPerDay)
        pos++
    }
    c[pos]--
    return c.any { it != 0 }
}


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader

fun main() {
    problemB(System.`in`)
}

fun problemB(inputStream: InputStream) {
    val time = System.nanoTime()
    val reader = BufferedReader(InputStreamReader(inputStream))
    val exampleCount = reader.readLine().toInt()
    for (i in 1..exampleCount) {
        val params = reader.readLine().split(" ").map { it.toInt() }
        val n = params[0]
        val k1 = params[1]
        val k2 = params[2]
        val dayOffs = reader.readLine().map { it.toString().toInt() }.toIntArray()
        solve(n, k1, k2, dayOffs)
    }
//    println("Performed in ${(System.nanoTime()-time)/10e6}ms")
}

fun solve(n: Int, k1: Int, k2: Int, dayOffs: IntArray) {
    val c = IntArray(n) { i -> if (dayOffs[i] == 0) 0 else k1 }

    var hasNext = true
    while (hasNext) {
//        println(Arrays.toString(c))
        val total = check(c, k2, dayOffs)
        if (total != null){
            println(total)
//        println(Arrays.toString(c))
        return
        }
        hasNext = next(c, k1, dayOffs, k2)
    }
}

fun check(c: IntArray, k2: Int, dayOffs: IntArray): Int? {
    for (i in 0..c.size-2) {
        if ((c[i]+c[i+1])>k2) return null
        if (c[i]>0 && dayOffs[i]==0) return null
    }
    if (c[c.size-1]>0 && dayOffs[c.size-1]==0) return null
    return c.sum()
}

fun next(c: IntArray, maxPerDay: Int, dayOffs: IntArray, k2: Int): Boolean {
    var pos = 0
    while (c[pos] == 0) {
        val cPrev = if (pos == 0) 0 else c[pos - 1]
        val cNext = if (pos == c.size-1) 0 else c[pos + 1]
        c[pos] = if (dayOffs[pos] == 0) 0 else minOf(k2-cPrev, k2-cNext+1, maxPerDay)
        pos++
    }
    c[pos]--
    return c.any { it != 0 }
}


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader

fun main() {
    problemB(System.`in`)
}

fun problemB(inputStream: InputStream) {
    val reader = BufferedReader(InputStreamReader(inputStream))
    val exampleCount = reader.readLine().toInt()
    for (i in 1..exampleCount) {
        val params = reader.readLine().split(" ").map { it.toInt() }
        val n = params[0]
        val k1 = params[1]
        val k2 = params[2]
        val dayOffs = reader.readLine().map { it.toString().toInt() }.toIntArray()
        solve(n, k1, k2, dayOffs)
    }
}

fun solve(n: Int, k1: Int, k2: Int, dayOffs: IntArray) {
    val c = IntArray(n, { i -> k1 })

    var hasNext = true
    while (hasNext) {
//        println(Arrays.toString(c))
        val total = check(c, k2, dayOffs)
        if (total != null){
            println(total)
//        println(Arrays.toString(c))
        return
        }
        hasNext = next(c, k1)
    }
}

fun check(c: IntArray, k2: Int, dayOffs: IntArray): Int? {
    for (i in 0..c.size-2) {
        if ((c[i]+c[i+1])>k2) return null
        if (c[i]>0 && dayOffs[i]==0) return null
    }
    if (c[c.size-1]>0 && dayOffs[c.size-1]==0) return null
    return c.sum()
}

fun next(c: IntArray, maxPerDay: Int): Boolean {
    var pos = 0
    while (c[pos] == 0) {
        c[pos] = maxPerDay
        pos++
    }
    c[pos]--
    return c.any { it != 0 }
}


fun main () {
    val t = readLine()!!.toInt()
    for(i in 1..t){
        val (n, k1, k2) = readLine()!!.split(' ').map(String::toInt)
        val b = readLine()!!
        var d = 0
        var an = 0
        var a = Array<Int>(2) {0}
        a[0] = k2 - k1
        a[1] = k1
        for(j in 0..n - 1)
        {
            if(b[j] == '1')
            {
                d++
                an += a[d % 2]
            }
            else
            {
                d = 0
            }
        }
        println(an)
    }
}


fun main () {
    val t = readLine()!!.toInt()
    for(i in 1..t){
    	var (n, a, b) = readLine()!!.split(' ').map(String::toInt)
        b = listOf(b, a * 2).min()!!
        var s = readLn()
        var p = 0
        var ans = 0
        for(c in s)
        {
            if(c == '0')
            {
                ans += b * (p / 2) + a * (p % 2)
                pre = 0;
            }
            else{
                p++
            }
        }
        ans += b * (p / 2) + a * (p % 2)
        println(ans)
    }
}


fun main () {
    val t = readLine()!!.toInt()
    for(i in 1..t){
    	var (n, a, b) = readLine()!!.split(' ').map(String::toInt)
        b = listOf(b, a * 2).min()!!
        var s = readLine()!!
        var p = 0
        var ans = 0
        for(c in s)
        {
            if(c == '0')
            {
                ans += b * (p / 2) + a * (p % 2)
                p = 0;
            }
            else{
                p++
            }
        }
        ans += b * (p / 2) + a * (p % 2)
        println(ans)
    }
}


fun main () {
    val t = readLine()!!.toInt()
    for(i in 1..t){
    	var (n, a, b) = readLine()!!.split(' ').map(String::toInt)
        b = listOf(b, a * 2).min()!!
        var s = readLn()
        var p = 0
        var ans = 0
        for(c in s)
        {
            if(c == '0')
            {
                ans += b * (p / 2) + a * (p % 2)
                p = 0;
            }
            else{
                p++
            }
        }
        ans += b * (p / 2) + a * (p % 2)
        println(ans)
    }
}


private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
   // read input
   var T = readInt()
   for(t in 1..T) {
    var (n, k1, k2) = readInts()
       k2 = listOf(k2, k1*2).min()!!
       var s = readLn()
       var pre = 0
       var ans = 0
       for(c in s)
       {
           if(c == '0')
           {
               ans += k2*(pre/2) + k1*(pre%2)
               pre = 0;
           }
           else pre++;
       }
       ans += k2*(pre/2) + k1*(pre%2)

       println(ans)
   }
}


private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
fun main()
{
    val t = readInt()
    for(i in 1..t)
    {

        val (n,k1,k2) = readInts()
        val b = readLine()!!
        var ans=0
        var cnt =0

        //println(n.toString() + " " + k1.toString() + " "+ k2.toString() + " " + b)

        var a = Array<Int>(2) {0}
        a[1]=k1
        a[0]=k2-k1

        for(j in 0..n-1)
        {
            if(b[j]=='1')
            {
                cnt++
                ans += a[cnt%2]
            }
            else cnt = 0

        }

        println(ans)

    }

}


private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
fun main()
{
   val t = readInt()
   for(i in 1..t)
   {

       val (n,k1,k2) = readInts()
       val b = readLine()!!
       var ans=0
       var cnt =0

       var a = Array<Int>(2) {0}
       a[1]=k1
       a[0]=k2-k1

       for(j in 0..n-1)
       {
           if(b[j]=='1')
           {
               cnt++
               ans += a[cnt%2]
           }
           else cnt = 0

       }

       println(ans)

   }

}


import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    var test = sc.nextInt()
    while(test>0)
    {

       var n = sc.nextInt()
       var k1 = sc.nextInt()
       var k2 = sc.nextInt()
       var str = readLine()!!
       var last =- 1
       var ans = 0
       for(bit in str)
       {
           if(bit == '1')
           {
              if(last>0)
              {
                  ans+=k1
                  last=k1
              }
              else
              {
                  ans += Math.min(k2,k1+last)
                  last = Math.min(k2,k1+last)
              }
           }
           else
           {
              last=0
           }
       }
       println("$ans")
       test--
    }

}


import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    var test = sc.nextInt()
    while(test>0)
    {

       var n = sc.nextInt()
       var k1 = sc.nextInt()
       var k2 = sc.nextInt()
       var str = readLine()!!
       var last =- 1
       var ans = 0
       for(bit in str)
       {
           if(bit == '1')
           {
              if(last>0)
              {
                  ans+=k1
                  last=k1
              }
              else
              {
                  ans += min(k2,k1+last)
                  last = min(k2,k1+last)
              }
           }
           else
           {
              last=0
           }
       }
       println("$ans")
       test--
    }

}


import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    var test = sc.nextInt()
    while(test>0)
    {

       var n = sc.nextInt()
       var k1 = sc.nextInt()
       var k2 = sc.nextInt()
       var str = readLine()!!
       var last =- 1
       var ans = 0
       for(bit in str)
       {
           if(item=='1')
           {
              if(last>0)
              {
                  ans+=k1
                  last=k1
              }
              else
              {
                  ans+=min(k2,k1+last)
                  last=min(k2,k1+last)
              }
           }
           else
           {
              last=0
           }
       }
       println("$ans")
       test--
    }

}


#include<bits/stdc++.h>
#define ll          int
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define cr(P)       cout<<P<<"\n";return;
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;

const ll N   =  505;

  ll n,m,k;
  vector<ll> adj[N];
  vector<ll>color(N), par(N), cyc;
  ll cyc_st , cyc_end, cycle;
  pii a;

stack<int> path;
void dfs(int node){
    path.push(node);
    color[node]=1;
    for(auto i:adj[node]){
        if(!cycle){
            if(color[i] == 1){
                cycle = 1;
                cyc.pb(i);
                while(!path.empty() && path.top()!=i){
                    cyc.pb(path.top());
                    path.pop();
                }
                cyc.pb(i);
                reverse(cyc.begin(), cyc.end());
            }
            else if(!color[i]) dfs(i);
        }
    }
    if(!cycle)
    path.pop(),color[node]=2;
}

 void check(ll v){
  color[v] = 1;
  if(cycle){
    return;
   }
  for(ll w : adj[v]){
    if(a.F == v and a.S == w)continue;
    if(color[w] == 1){
      cycle = 1;
      return;
    }
    if(color[w] == 0){
     check(w);
    }
  }
  color[v] = 2; // BLACK
 }

void solve(){

  ll x=0,y=0,c=0,ans=0;
  cin>>n >> m;
  for (ll i = 0; i < m; ++i){
      cin >> x >> y;
      adj[x].pb(y);
  }
  for (ll i = 1; i <= n; ++i){
      if(color[i]==0 and cycle==0)  dfs(i);
  }
  if(!cycle){
    cr("YES");
  }

  for(ll i = 0; i+1<sz(cyc);i++){
   x = cyc[i];
   y = cyc[i+1];
   a = {x,y};
   for (ll i = 1; i <= n; ++i){
       color[i] = 0;
   }
   cycle = 0;
   for (ll i = 1; i <= n; ++i){
      if(color[i]==0) {
       check(i);
     }
  }

   if(cycle == 0){

     cr("YES");
   }

  }
  cr("NO");

}

signed main(){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //ll T;cin >> T;while (T--)
  solve();
  return 0;
}


#include<bits/stdc++.h>
#define ll          int
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define cr(P)       cout<<P<<"\n";return;
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;

const ll N   =  505;

  ll n,m,k;
  vector<ll> adj[N];
  vector<ll>color(N), par(N);
  ll cyc_st , cyc_end, cycle=1;
  pii a;

  void dfs(ll v){
  color[v] = 1; // GREY

  for(ll w : adj[v]){
    if(color[w] == 1){
      cycle = 1;
      cyc_st = w;
      cyc_end = v;
      return;
    }
    if(color[w] == 0){
     par[w] = v;
     dfs(w);
    }
  }
  color[v] = 2; // BLACK
 }

 void check(ll v){
  color[v] = 1;
  if(cycle){
    cr("YES");
    exit(0);
   }
  for(ll w : adj[v]){
    if(a.F == v and a.S == w)continue;
    if(color[w] == 1){
      cycle = 1;
      return;
    }
    if(color[w] == 0){
     check(w);
    }
  }
  color[v] = 2; // BLACK
 }

void solve(){

  ll x=0,y=0,c=0,ans=0;
  cin>>n >> m;
  for (ll i = 0; i < m; ++i){
      cin >> x >> y;
      adj[x].pb(y);
  }
  for (ll i = 1; i <= n; ++i){
      if(color[i]==0)  dfs(i);
  }
  if(!cycle){
    cr("YES");
  }
  vector<ll> cyc;
  cyc.pb(cyc_st);
  for (ll v = cyc_end; v != cyc_st; v = par[v]){
            cyc.pb(v);
        }
  cyc.push_back(cyc_st);
  reverse(cyc.begin(), cyc.end());
  for(ll i = 0; i+1<sz(cyc);i++){
   x = cyc[i];
   y = cyc[i+1];
   a = {x,y};
   for (ll i = 1; i <= n; ++i){
       color[i] = 0;
   }
   cycle = 0;
   for (ll i = 1; i <= n; ++i){
      if(color[i]==0) {
       check(i);
     }
  }

   if(cycle == 0){

     cr("YES");
   }

  }
  cr("NO");

}

signed main(){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //ll T;cin >> T;while (T--)
  solve();
  return 0;
}


#include<bits/stdc++.h>
#define ll          int
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define cr(P)       cout<<P<<"\n";return;
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;

const ll N   =  100005;

  ll n,m,k;
  vector<ll> adj[N];
  vector<ll>color(N), par(N);
  ll cyc_st , cyc_end, cycle=1;
  pii a;

  void dfs(ll v){
  color[v] = 1; // GREY
  for(ll w : adj[v]){
    if(color[w] == 1){
      cycle = 1;
      cyc_st = w;
      cyc_end = v;
      return;
    }
    if(color[w] == 0){
     par[w] = v;
     dfs(w);
    }
  }
  color[v] = 2; // BLACK
 }

 void check(ll v){
  color[v] = 1;

  for(ll w : adj[v]){
    if(a.F == v and a.S == w)continue;
    if(color[w] == 1){
      cycle = 1;
      return;
    }
    if(color[w] == 0){
     check(w);
    }
  }
  color[v] = 2; // BLACK
 }

void solve(){

  ll x=0,y=0,c=0,ans=0;
  cin>>n >> m;
  for (ll i = 0; i < m; ++i){
      cin >> x >> y;
      adj[x].pb(y);
  }
  for (ll i = 1; i <= n; ++i){
      if(color[i]==0)  dfs(i);
  }
  if(!cycle){
    cr("YES");
  }
  vector<ll> cyc;
  cyc.pb(cyc_st);
  for (ll v = cyc_end; v != cyc_st; v = par[v]){
            cyc.pb(v);
        }
  cyc.push_back(cyc_st);
  reverse(cyc.begin(), cyc.end());
  for(ll i = 0; i+1<sz(cyc);i++){
   x = cyc[i];
   y = cyc[i+1];
   a = {x,y};
   for (ll i = 1; i <= n; ++i){
       color[i] = 0;
   }
   cycle = 0;
   for (ll i = 1; i <= n; ++i){
      if(color[i]==0) {
       check(i);
     }
  }

   if(cycle == 0){

     cr("YES");
   }

  }
  cr("NO");

}

signed main(){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //ll T;cin >> T;while (T--)
  solve();
  return 0;
}


#include<bits/stdc++.h>
#define ll          int
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define cr(P)       cout<<P<<"\n";return;
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;

const ll N   =  505;

  ll n,m,k;
  vector<ll> adj[N];
  vector<ll>color(N), par(N),cyc,v(N);
  ll cyc_st , cyc_end, cycle;
  pii a;

stack<int> path;
void dfs(int node){
    path.push(node);
    color[node]=1;
    for(auto i:adj[node]){
        if(!cycle){
            if(color[i] == 1){
                cycle = 1;
                cyc.pb(i);
                while(!path.empty() && path.top()!=i){
                    cyc.pb(path.top());
                    path.pop();
                }
                cyc.pb(i);
                reverse(cyc.begin(), cyc.end());
            }
            else if(!v[i]) dfs(i);
        }
    }
    if(!cycle)
    path.pop(),color[node]=2;
}

 void check(ll v){
  color[v] = 1;
  if(cycle){
    return;
   }
  for(ll w : adj[v]){
    if(a.F == v and a.S == w)continue;
    if(color[w] == 1){
      cycle = 1;
      return;
    }
    if(color[w] == 0){
     check(w);
    }
  }
  color[v] = 2; // BLACK
 }

void solve(){

  ll x=0,y=0,c=0,ans=0;
  cin>>n >> m;
  for (ll i = 0; i < m; ++i){
      cin >> x >> y;
      adj[x].pb(y);
  }
  for (ll i = 1; i <= n; ++i){
      if(color[i]==0 and cycle==0)  dfs(i);
  }
  if(!cycle){
    cr("YES");
  }

  for(ll i = 0; i+1<sz(cyc);i++){
   x = cyc[i];
   y = cyc[i+1];
   a = {x,y};
   for (ll i = 1; i <= n; ++i){
       color[i] = 0;
   }
   cycle = 0;
   for (ll i = 1; i <= n; ++i){
      if(color[i]==0) {
       check(i);
     }
  }

   if(cycle == 0){

     cr("YES");
   }

  }
  cr("NO");

}

signed main(){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //ll T;cin >> T;while (T--)
  solve();
  return 0;
}


#include<bits/stdc++.h>
#define ll          int
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define cr(P)       cout<<P<<"\n";return;
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;

const ll N   =  505;

  ll n,m,k;
  vector<ll> adj[N];
  vector<ll>color(N), par(N);
  ll p_st , p_end, ple;

  int v[505],c[505],f,mark[505][505];

  void dfs(ll v){
  color[v] = 1; // GREY
  if(ple){
    return;
  }
  for(ll w : adj[v]){
    if(color[w] == 1){
      ple = 1;
      p_st = w;
      p_end = v;
      return;
    }
    if(color[w] == 0){
     par[w] = v;
     dfs(w);
    }
  }
  color[v] = 2; // BLACK
 }

void check(int node){
    v[node]=1;
    c[node]=1;
    for(auto i:adj[node]){
        if(mark[node][i]) continue;
        if(!v[i]) check(i);
        else if(c[i]) f=1;
    }
    c[node]=0;
}

void solve(){

  ll x=0,y=0,ans=0;
  cin>>n >> m;
  for (ll i = 0; i < m; ++i){
      cin >> x >> y;
      adj[x].pb(y);
  }
  for (ll i = 1; i <= n; ++i){
      if(color[i]==0 and ple==0)  dfs(i);
  }
  if(!ple){
    cr("YES");
  }
  vector<ll> p;
  p.pb(p_st);
  for (ll v = p_end; v != p_st; v = par[v]){
            p.pb(v);
        }
  p.push_back(p_st);
  reverse(p.begin(), p.end());
   fr(i,0,sz(p)-1){
            mark[p[i]][p[i+1]]=1;
            memset(v,0,sizeof v);
            f=0;
            fr(j,1,n+1){
                if(v[j]==1) continue;
                memset(c,0,sizeof c);
                check(j);
                if(f) break;
            }
            if(!f){
                cout<<"YES";
                return;
            }
            mark[p[i]][p[i+1]]=0;
        }
        cout<<"NO";

}

signed main(){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //ll T;cin >> T;while (T--)
  solve();
  return 0;
}


#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define cr(P)       cout<<P<<"\n";return;
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;

const ll N   =  100005;

  ll n,m,k;
  vector<ll> adj[N];
  vector<ll>color(N), par(N);
  ll cyc_st , cyc_end, cycle=1;
  mii mp;

  void dfs(ll v){
  color[v] = 1; // GREY
  for(ll w : adj[v]){
    if(color[w] == 1){
      cycle = 1;
      cyc_st = w;
      cyc_end = v;
      return;
    }
    if(color[w] == 0){
     par[w] = v;
     dfs(w);
    }
  }
  color[v] = 2; // BLACK
 }

 void check(ll v){
  color[v] = 1;

  for(ll w : adj[v]){
    if(mp[{v,w}])continue;
    if(color[w] == 1){
     // cout << cycle << '\n';
      cycle = 1;
      return;
    }
    if(color[w] == 0){
     check(w);
    }
  }
  color[v] = 2; // BLACK
 }

void solve(){

  ll x=0,y=0,c=0,ans=0;
  cin>>n >> m;
  for (ll i = 0; i < m; ++i){
      cin >> x >> y;
      adj[x].pb(y);
  }
  for (ll i = 1; i <= n; ++i){
      if(color[i]==0)  dfs(i);
  }
  if(!cycle){
    cr("YES");
  }
  vector<ll> cyc;
  cyc.pb(cyc_st);
  for (ll v = cyc_end; v != cyc_st; v = par[v]){
            cyc.pb(v);
        }
  cyc.push_back(cyc_st);
  reverse(cyc.begin(), cyc.end());
  for(ll i = 0; i+1<sz(cyc);i++){
   x = cyc[i];
   y = cyc[i+1];
   mp[{x,y}] = 1;
   for (ll i = 1; i <= n; ++i){
       color[i] = 0;
   }
   cycle = 0;
   for (ll i = 1; i <= n; ++i){
      if(color[i]==0) {
       check(i);
     }
  }

   if(cycle == 0){

     cr("YES");
   }
   mp[{x,y}] = 0;
  }
  cr("NO");

}

signed main(){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //ll T;cin >> T;while (T--)
  solve();
  return 0;
}


#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define cr(P)       cout<<P<<"\n";return;
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;

const ll N   =  500005;
const ll mod = 1e9 + 7;
  ll n,m,k;
  vector<ll> adj[N];
  vector<ll>color(N), par(N);
  ll cyc_st , cyc_end, cycle=1;
  mii mp;

  void dfs(ll v){
  color[v] = 1; // GREY
  for(ll w : adj[v]){
    if(color[w] == 1){
      cycle = 1;
      cyc_st = w;
      cyc_end = v;
      return;
    }
    if(color[w] == 0){
     par[w] = v;
     dfs(w);
    }
  }
  color[v] = 2; // BLACK
 }

 void check(ll v){
  color[v] = 1;

  for(ll w : adj[v]){
    if(mp[{v,w}])continue;
    if(color[w] == 1){
     // cout << cycle << '\n';
      cycle = 1;
      return;
    }
    if(color[w] == 0){
     check(w);
    }
  }
  color[v] = 2; // BLACK
 }

void solve(){

  ll x=0,y=0,c=0,ans=0;
  cin>>n >> m;
  for (ll i = 0; i < m; ++i){
      cin >> x >> y;
      adj[x].pb(y);
  }
  for (ll i = 1; i <= n; ++i){
      if(color[i]==0)  dfs(i);
  }
  if(!cycle){
    cr("YES");
  }
  vector<ll> cyc;
  cyc.pb(cyc_st);
  for (ll v = cyc_end; v != cyc_st; v = par[v]){
            cyc.pb(v);
        }
  cyc.push_back(cyc_st);
  reverse(cyc.begin(), cyc.end());
  for(ll i = 0; i+1<sz(cyc);i++){
   x = cyc[i];
   y = cyc[i+1];
   mp[{x,y}] = 1;
   for (ll i = 1; i <= n; ++i){
       color[i] = 0;
   }
   cycle = 0;
   for (ll i = 1; i <= n; ++i){
      if(color[i]==0) {
       check(i);
     }
  }

   if(cycle == 0){

     cr("YES");
   }
   mp[{x,y}] = 0;
  }
  cr("NO");

}

signed main(){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //ll T;cin >> T;while (T--)
  solve();
  return 0;
}


#include<bits/stdc++.h>
#define ll          int
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define cr(P)       cout<<P<<"\n";return;
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;

const ll N   =  505;

  ll n,m,k;
  vector<ll> adj[N];
  vector<ll>color(N), par(N);
  ll cyc_st , cyc_end, cycle;
  pii a;

  void dfs(ll v){
  color[v] = 1; // GREY
  if(cycle){
    return;
  }
  for(ll w : adj[v]){
    if(color[w] == 1){
      cycle = 1;
      cyc_st = w;
      cyc_end = v;
      return;
    }
    if(color[w] == 0){
     par[w] = v;
     dfs(w);
    }
  }
  color[v] = 2; // BLACK
 }

 void check(ll v){
  color[v] = 1;
  if(cycle){
    return;
   }
  for(ll w : adj[v]){
    if(a.F == v and a.S == w)continue;
    if(color[w] == 1){
      cycle = 1;
      return;
    }
    if(color[w] == 0){
     check(w);
    }
  }
  color[v] = 2; // BLACK
 }

void solve(){

  ll x=0,y=0,c=0,ans=0;
  cin>>n >> m;
  for (ll i = 0; i < m; ++i){
      cin >> x >> y;
      adj[x].pb(y);
  }
  for (ll i = 1; i <= n; ++i){
      if(color[i]==0 and cycle==0)  dfs(i);
  }
  if(!cycle){
    cr("YES");
  }
  vector<ll> cyc;
  cyc.pb(cyc_st);
  for (ll v = cyc_end; v != cyc_st; v = par[v]){
            cyc.pb(v);
        }
  cyc.push_back(cyc_st);
  reverse(cyc.begin(), cyc.end());
  for(ll i = 0; i+1<sz(cyc);i++){
   x = cyc[i];
   y = cyc[i+1];
   a = {x,y};
   for (ll i = 1; i <= n; ++i){
       color[i] = 0;
   }
   cycle = 0;
   for (ll i = 1; i <= n; ++i){
      if(color[i]==0) {
       check(i);
     }
  }

   if(cycle == 0){

     cr("YES");
   }

  }
  cr("NO");

}

signed main(){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //ll T;cin >> T;while (T--)
  solve();
  return 0;
}


#include<bits/stdc++.h>
#define ll          int
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define cr(P)       cout<<P<<"\n";return;
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;

const ll N   =  505;

  ll n,m,k;
  vector<ll> adj[N];
  vector<ll>color(N), par(N);
  ll cyc_st , cyc_end, cycle=1;
  pii a;

  void dfs(ll v){
  color[v] = 1; // GREY
  for(ll w : adj[v]){
    if(color[w] == 1){
      cycle = 1;
      cyc_st = w;
      cyc_end = v;
      return;
    }
    if(color[w] == 0){
     par[w] = v;
     dfs(w);
    }
  }
  color[v] = 2; // BLACK
 }

 void check(ll v){
  color[v] = 1;

  for(ll w : adj[v]){
    if(a.F == v and a.S == w)continue;
    if(color[w] == 1){
      cycle = 1;
      return;
    }
    if(color[w] == 0){
     check(w);
    }
  }
  color[v] = 2; // BLACK
 }

void solve(){

  ll x=0,y=0,c=0,ans=0;
  cin>>n >> m;
  for (ll i = 0; i < m; ++i){
      cin >> x >> y;
      adj[x].pb(y);
  }
  for (ll i = 1; i <= n; ++i){
      if(color[i]==0)  dfs(i);
  }
  if(!cycle){
    cr("YES");
  }
  vector<ll> cyc;
  cyc.pb(cyc_st);
  for (ll v = cyc_end; v != cyc_st; v = par[v]){
            cyc.pb(v);
        }
  cyc.push_back(cyc_st);
  reverse(cyc.begin(), cyc.end());
  for(ll i = 0; i+1<sz(cyc);i++){
   x = cyc[i];
   y = cyc[i+1];
   a = {x,y};
   for (ll i = 1; i <= n; ++i){
       color[i] = 0;
   }
   cycle = 0;
   for (ll i = 1; i <= n; ++i){
      if(color[i]==0) {
       check(i);
     }
  }

   if(cycle == 0){

     cr("YES");
   }

  }
  cr("NO");

}

signed main(){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //ll T;cin >> T;while (T--)
  solve();
  return 0;
}


#include<bits/stdc++.h>
#define ll          int
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define cr(P)       cout<<P<<"\n";return;
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;

const ll N   =  100005;

  ll n,m,k;
  vector<ll> adj[N];
  vector<ll>color(N), par(N);
  ll cyc_st , cyc_end, cycle=1;
  mii mp;

  void dfs(ll v){
  color[v] = 1; // GREY
  for(ll w : adj[v]){
    if(color[w] == 1){
      cycle = 1;
      cyc_st = w;
      cyc_end = v;
      return;
    }
    if(color[w] == 0){
     par[w] = v;
     dfs(w);
    }
  }
  color[v] = 2; // BLACK
 }

 void check(ll v){
  color[v] = 1;

  for(ll w : adj[v]){
    if(mp[{v,w}])continue;
    if(color[w] == 1){
     // cout << cycle << '\n';
      cycle = 1;
      return;
    }
    if(color[w] == 0){
     check(w);
    }
  }
  color[v] = 2; // BLACK
 }

void solve(){

  ll x=0,y=0,c=0,ans=0;
  cin>>n >> m;
  for (ll i = 0; i < m; ++i){
      cin >> x >> y;
      adj[x].pb(y);
  }
  for (ll i = 1; i <= n; ++i){
      if(color[i]==0)  dfs(i);
  }
  if(!cycle){
    cr("YES");
  }
  vector<ll> cyc;
  cyc.pb(cyc_st);
  for (ll v = cyc_end; v != cyc_st; v = par[v]){
            cyc.pb(v);
        }
  cyc.push_back(cyc_st);
  reverse(cyc.begin(), cyc.end());
  for(ll i = 0; i+1<sz(cyc);i++){
   x = cyc[i];
   y = cyc[i+1];
   mp[{x,y}] = 1;
   for (ll i = 1; i <= n; ++i){
       color[i] = 0;
   }
   cycle = 0;
   for (ll i = 1; i <= n; ++i){
      if(color[i]==0) {
       check(i);
     }
  }

   if(cycle == 0){

     cr("YES");
   }
   mp[{x,y}] = 0;
  }
  cr("NO");

}

signed main(){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //ll T;cin >> T;while (T--)
  solve();
  return 0;
}


#include<bits/stdc++.h>
#define ll          int
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define cr(P)       cout<<P<<"\n";return;
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;

const ll N   =  505;

  ll n,m,k;
  vector<ll> adj[N];
  vector<ll>color(N), par(N);
  ll cyc_st , cyc_end, cycle=1;
  pii a;

  void dfs(ll v){
  color[v] = 1; // GREY
  if(cycle)return;
  for(ll w : adj[v]){
    if(color[w] == 1){
      cycle = 1;
      cyc_st = w;
      cyc_end = v;
      return;
    }
    if(color[w] == 0){
     par[w] = v;
     dfs(w);
    }
  }
  color[v] = 2; // BLACK
 }

 void check(ll v){
  color[v] = 1;
  if(cycle)return;

  for(ll w : adj[v]){
    if(a.F == v and a.S == w)continue;
    if(color[w] == 1){
      cycle = 1;
      return;
    }
    if(color[w] == 0){
     check(w);
    }
  }
  color[v] = 2; // BLACK
 }

void solve(){

  ll x=0,y=0,c=0,ans=0;
  cin>>n >> m;
  for (ll i = 0; i < m; ++i){
      cin >> x >> y;
      adj[x].pb(y);
  }
  for (ll i = 1; i <= n; ++i){
      if(color[i]==0)  dfs(i);
  }
  if(!cycle){
    cr("YES");
  }
  vector<ll> cyc;
  cyc.pb(cyc_st);
  for (ll v = cyc_end; v != cyc_st; v = par[v]){
            cyc.pb(v);
        }
  cyc.push_back(cyc_st);
  reverse(cyc.begin(), cyc.end());
  for(ll i = 0; i+1<sz(cyc);i++){
   x = cyc[i];
   y = cyc[i+1];
   a = {x,y};
   for (ll i = 1; i <= n; ++i){
       color[i] = 0;
   }
   cycle = 0;
   for (ll i = 1; i <= n; ++i){
      if(color[i]==0) {
       check(i);
     }
  }

   if(cycle == 0){

     cr("YES");
   }

  }
  cr("NO");

}

signed main(){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //ll T;cin >> T;while (T--)
  solve();
  return 0;
}


#include<bits/stdc++.h>
#define ll          int
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define cr(P)       cout<<P<<"\n";return;
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;

const ll N   =  505;

  ll n,m,k;
  vector<ll> adj[N];
  vector<ll>color(N), par(N),cyc,v(N);
  ll cyc_st , cyc_end, cycle,f;
  pii a;

stack<int> path;
void dfs(int node){
    path.push(node);
    v[node]=1;
    color[node]=1;
    for(auto i:adj[node]){
        if(!f){
            if(v[i] && color[i]){
                f=1;
                cyc.pb(i);
                while(!path.empty() && path.top()!=i){
                    cyc.pb(path.top());
                    path.pop();
                }
                cyc.pb(i);
                reverse(cyc.begin(), cyc.end());
            }
            else if(!v[i]) dfs(i);
        }
    }
    if(!f)
    path.pop(),color[node]=0;
}

 void check(ll v){
  color[v] = 1;
  if(cycle){
    return;
   }
  for(ll w : adj[v]){
    if(a.F == v and a.S == w)continue;
    if(color[w] == 1){
      cycle = 1;
      return;
    }
    if(color[w] == 0){
     check(w);
    }
  }
  color[v] = 2; // BLACK
 }

void solve(){

  ll x=0,y=0,c=0,ans=0;
  cin>>n >> m;
  for (ll i = 0; i < m; ++i){
      cin >> x >> y;
      adj[x].pb(y);
  }
  for (ll i = 1; i <= n; ++i){
      if(color[i]==0 and cycle==0)  dfs(i);
  }
  if(!f){
    cr("YES");
  }

  for(ll i = 0; i+1<sz(cyc);i++){
   x = cyc[i];
   y = cyc[i+1];
   a = {x,y};
   for (ll i = 1; i <= n; ++i){
       color[i] = 0;
   }
   cycle = 0;
   for (ll i = 1; i <= n; ++i){
      if(color[i]==0) {
       check(i);
     }
  }

   if(cycle == 0){

     cr("YES");
   }

  }
  cr("NO");

}

signed main(){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //ll T;cin >> T;while (T--)
  solve();
  return 0;
}


    #include <bits/stdc++.h>

    #define ll          long long
    #define pb          push_back
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define vii         vector<pii>
    #define mi          map<int,int>
    #define mii         map<int,pii>
    #define all(a)      (a).begin(),(a).end()
    #define x           first
    #define y           second
    #define sz(x)       (int)x.size()
    #define hell        1000000007
    #define endl        '\n'
    #define rep(i,a,b)  for(int i=a;i<b;i++)
    using namespace std;
    vi a[505],p;
    int v[505],c[505],f,mark[505][505];
    stack<int> path;
    void dfs(int node){
        path.push(node);
        v[node]=1;
        c[node]=1;
        for(auto i:a[node]){
            if(!f){
                if(v[i] && c[i]){
                    f=1;
                    p.pb(i);
                    while(!path.empty() && path.top()!=i){
                        p.pb(path.top());
                        path.pop();
                    }
                    p.pb(i);
                    reverse(all(p));
                }
                else if(!v[i]) dfs(i);
            }
        }
        if(!f)
        path.pop(),c[node]=0;
    }
    void check(int node){
        v[node]=1;
        c[node]=1;
        for(auto i:a[node]){
            if(mark[node][i]) continue;
            if(!v[i]) check(i);
            else if(c[i]) f=1;
        }
        c[node]=0;
    }
    void solve()
    {
        int n,m;
        cin>>n>>m;
        rep(i,0,m){
            int x,y;
            cin>>x>>y;
            a[x].pb(y);
        }
        rep(i,1,n+1)
        if(!v[i] && !f){
            memset(c,0,sizeof c);
            dfs(i);
        }
        if(sz(p)==0) {cout<<"YES";return;}
        for (ll i = 0; i < sz(p); ++i){
          cout << p[i] <<" ";
        }
        return;
        rep(i,0,sz(p)-1){
            mark[p[i]][p[i+1]]=1;
            memset(v,0,sizeof v);
            f=0;
            rep(j,1,n+1){
                if(v[j]==1) continue;
                memset(c,0,sizeof c);
                check(j);
                if(f) break;
            }
            if(!f){
                cout<<"YES";
                return;
            }
            mark[p[i]][p[i+1]]=0;
        }
        cout<<"NO";
    }

    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int t=1;
    //    cin>>t;
        while(t--)
            solve();
        return 0;
    }


#include<bits/stdc++.h>
#define ll          int
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define cr(P)       cout<<P<<"\n";return;
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;

const ll N   =  505;

  ll n,m,k;
  vector<ll> adj[N];
  vector<ll>color(N), par(N);
  ll cyc_st , cyc_end, cycle=1;
  pii a;

  void dfs(ll v){
  color[v] = 1; // GREY

  for(ll w : adj[v]){
    if(color[w] == 1){
      cycle = 1;
      cyc_st = w;
      cyc_end = v;
      return;
    }
    if(color[w] == 0){
     par[w] = v;
     dfs(w);
    }
  }
  color[v] = 2; // BLACK
 }

 void check(ll v){
  color[v] = 1;
  if(cycle){
    return;
   }
  for(ll w : adj[v]){
    if(a.F == v and a.S == w)continue;
    if(color[w] == 1){
      cycle = 1;
      return;
    }
    if(color[w] == 0){
     check(w);
    }
  }
  color[v] = 2; // BLACK
 }

void solve(){

  ll x=0,y=0,c=0,ans=0;
  cin>>n >> m;
  for (ll i = 0; i < m; ++i){
      cin >> x >> y;
      adj[x].pb(y);
  }
  for (ll i = 1; i <= n; ++i){
      if(color[i]==0)  dfs(i);
  }
  if(!cycle){
    cr("YES");
  }
  vector<ll> cyc;
  cyc.pb(cyc_st);
  for (ll v = cyc_end; v != cyc_st; v = par[v]){
            cyc.pb(v);
        }
  cyc.push_back(cyc_st);
  reverse(cyc.begin(), cyc.end());
  for(ll i = 0; i+1<sz(cyc);i++){
   x = cyc[i];
   y = cyc[i+1];
   a = {x,y};
   for (ll i = 1; i <= n; ++i){
       color[i] = 0;
   }
   cycle = 0;
   for (ll i = 1; i <= n; ++i){
      if(color[i]==0) {
       check(i);
     }
  }

   if(cycle == 0){

     cr("YES");
   }

  }
  cr("NO");

}

signed main(){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //ll T;cin >> T;while (T--)
  solve();
  return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define N 505
#define md int(1000000007)
#define pb push_back
#define fi first
#define sc second
#define pp pair <int, int>

int arr[N] = {0};
vector < int > g[N];
vector < int > v;
set < int > s;
map < pp, int > mp;

void dfs(int x, int ct){
	//cout << x <<" " << ct << endl;
	arr[x] = ct;
	v.pb(x);
	s.insert(x);
	for(int i : g[x]){
		if(arr[i] == ct && s.find(i) != s.end()){
			mp[{x,i}]++;
			for(int j = v.size() - 1 ; j >0 ; j--){
				mp[{v[j-1],v[j]}]++;
				if(v[j-1] == i) break;
			}
			continue;
		}
		if(arr[i] == 0) dfs(i,ct);
	}
	s.erase(x);
	v.erase(v.begin() + v.size() -1);
}

int main(){

	ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n,m; cin >> n >> m;

	int x,y;
	int ct = 0;
	for(int i = 1; i <=m ; i ++){
		cin >> x >> y;
		mp[{x,y}] = 1;
		if(mp.find({y,x}) != mp.end()) ct++;
		g[x].pb(y);
	}
	//cout << endl;
	if(ct > 1){
		cout << "NO" << endl;
		return 0;
	}
	mp.clear();

	ct = 1;
	for(int i = 1 ; i<=n ; i++){
		if(arr[i] == 0){dfs(i,ct); ct++;}
	}

	int mx = 0;
	pp p;
	for(auto i : mp){
		//cout << i.fi.fi <<" " << i.fi.sc <<"  " << i.sc << endl;
		if(i.sc > mx){
			p = i.fi;
			mx = i.sc;
		}
	}
	if(mx == 0){
		cout << "YES" << endl;
		return 0;
	}

	v.clear(); mp.clear();
	fill(arr, arr+N, 0);

	//cout << "rmv " << p.fi << ' '  << p.sc <<endl;
	for(int i = 0; i <g[p.fi].size() ; i++){
		if(g[p.fi][i] == p.sc){
			g[p.fi].erase(g[p.fi].begin() + i);
			break;
		}
	}

	/*for(int i =1 ; i <=n ; i ++){
		cout << i <<"  ";
		for(int j : g[i]){
			cout << j <<" ";
		}
		cout << endl;
	}*/

	ct = 1;
	for(int i = 1 ; i <= n ; i++){
		if(arr[i] == 0){dfs(i,ct); ct++;}
	}

	/*cout << endl;
	for(auto i : mp){
		cout << i.fi.fi <<" " << i.fi.sc <<"  " << i.sc << endl;
	}*/

	if(mp.empty()){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}

	return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define N 505
#define md int(1000000007)
#define pb push_back
#define fi first
#define sc second
#define pp pair <int, int>

int arr[N] = {0};
vector < int > g[N];
vector < int > v;
set < int > s;
map < pp, int > mp;
int y = 0;

void dfs(int x){
	//cout << x << "  ";
	arr[x] = 1;
	v.pb(x);
	s.insert(x);
	for(int i : v){
		//cout << i <<" ";
	}
	//cout << endl;
	for(int i : g[x]){
		if(arr[i] == 1 && s.find(i) != s.end()){
			mp[{x,i}]++;
			for(int j = v.size() - 1 ; j >0 ; j--){
				mp[{v[j-1],v[j]}]++;
				if(v[j-1] == i) break;
			}
			y = 1;
			return ;
		}
		if(arr[i] == 0) dfs(i);
		if(y == 1) return;
	}
	s.erase(x);
	v.erase(v.begin() + v.size() -1);
}

int main(){

	ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n,m; cin >> n >> m;

	int x,y;
	int ct = 0;
	for(int i = 1; i <=m ; i ++){
		cin >> x >> y;
		mp[{x,y}] = 1;
		if(mp.find({y,x}) != mp.end()) ct++;
		g[x].pb(y);
	}
	//cout << endl;
	if(ct > 1){
		cout << "NO" << endl;
		return 0;
	}
	mp.clear();

	y = 0;
	for(int i = 1 ; i<=n ; i++){
		if(arr[i] == 0){dfs(i);}
	}
	if(y ==0){
		cout << "YES" << endl;
		return 0;
	}

	for(auto i : mp){
		for(int j = 0 ; j < g[i.fi.fi].size(); j++){
			if(g[i.fi.fi][j] == i.fi.sc){
				g[i.fi.fi].erase(g[i.fi.fi].begin() + j);
			}
		}
		fill(arr,arr+N, 0);
		y = 0;
		for(int j = 1 ; j <=n ; j++){
			if(arr[j]) dfs(j);
		}
		if(y == 0){
			cout <<"YES" << endl;
			return 0;
		}
		g[i.fi.fi].pb(i.fi.sc);
	}

	cout << "NO" << endl;

	return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define N 505
#define md int(1000000007)
#define pb push_back
#define fi first
#define sc second
#define pp pair <int, int>

int arr[N] = {0};
vector < int > g[N];
vector < int > v;
set < int > s;
map < pp, int > mp;
int y = 0;

void dfs(int x){
	//cout << x << "  ";
	arr[x] = 1;
	v.pb(x);
	s.insert(x);
	for(int i : v){
	//	cout << i <<" ";
	}
	//cout << endl;
	for(int i : g[x]){
		if(y) return ;
		if(arr[i] == 1 && s.find(i) != s.end()){
			//cout << "YEAH " << x <<" " << i<< endl;
			mp[{x,i}]++;
			for(int j = v.size() - 1 ; j >0 ; j--){
				mp[{v[j-1],v[j]}]++;
				if(v[j-1] == i) break;
			}
			y = 1;
			//cout <<"y " <<  y << endl;
			return ;
		}
		if(arr[i] == 0) dfs(i);
	}
	s.erase(x);
	v.erase(v.begin() + v.size() -1);
}

int main(){

	ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n,m; cin >> n >> m;

	int x,ya;
	int ct = 0;
	for(int i = 1; i <=m ; i ++){
		cin >> x >> ya;
		mp[{x,ya}] = 1;
		if(mp.find({ya,x}) != mp.end()) ct++;
		g[x].pb(ya);
	}
	//cout << endl;
	if(ct > 1){
		cout << "NO" << endl;
		return 0;
	}
	mp.clear();

	y = 0;
	for(int i = 1 ; i<=n ; i++){
		if(arr[i] == 0 && y == 0){dfs(i);}
	}
	if(y ==0){
		cout << "YES" << endl;
		return 0;
	}

	//cout << endl;
	for(auto i : mp){
	//	cout << i.fi.fi <<" " << i.fi.sc <<"  " << i.sc << endl;
	}

	for(auto i : mp){
		for(int j = 0 ; j < g[i.fi.fi].size(); j++){
			if(g[i.fi.fi][j] == i.fi.sc){
				g[i.fi.fi].erase(g[i.fi.fi].begin() + j);
				break;
			}
		}
		fill(arr,arr+N, 0);
		y = 0;
		for(int j = 1 ; j <=n ; j++){
			if(arr[j]) dfs(j);
		}
		if(y == 0){
			cout <<"YES" << endl;
			return 0;
		}
		g[i.fi.fi].pb(i.fi.sc);
	}

	cout << "NO" << endl;

	return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define N 100005
#define md int(1000000007)
#define pb push_back
#define fi first
#define sc second
#define pp pair <int, int>

int arr[N] = {0};
vector < int > g[N];
vector < int > v;
map < pp, int > mp;

void dfs(int x){
	arr[x] = 1;
	v.pb(x);
	for(int i : g[x]){
		if(arr[i]){
			mp[{x,i}]++;
			for(int j = v.size() - 1 ; j >0 ; j--){
				mp[{v[j-1],v[j]}]++;
				if(v[j-1] == i) break;
			}
			continue;
		}
		dfs(i);
	}
	v.erase(v.begin() + v.size() -1);
	arr[x] = 0;
}

int main(){

	ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n,m; cin >> n >> m;

	int x,y;
	for(int i = 1; i <=m ; i ++){
		cin >> x >> y;
		g[x].pb(y);
	}

	for(int i = 1 ; i<=n ; i++){
		if(!arr[i]) dfs(i);
	}

	int mx = 0;
	pp p;
	for(auto i : mp){
		//cout << i.fi.fi <<" " << i.fi.sc <<"  " << i.sc << endl;
		if(i.sc > mx){
			p = i.fi;
			mx = i.sc;
		}
	}
	if(mx == 0){
		cout << "YES" << endl;
		return 0;
	}

	v.clear(); mp.clear();
	fill(arr, arr+N, 0);

	//cout << "rmv " << p.fi << ' '  << p.sc <<endl;
	for(int i = 0; i <g[p.fi].size() ; i++){
		if(g[p.fi][i] == p.sc){
			g[p.fi].erase(g[p.fi].begin() + i);
			break;
		}
	}

	/*for(int i =1 ; i <=n ; i ++){
		cout << i <<"  ";
		for(int j : g[i]){
			cout << j <<" ";
		}
		cout << endl;
	}*/

	for(int i = 1 ; i <= n ; i++){
		if(!arr[i]) dfs(i);
	}

	if(mp.empty()){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}

	return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define N 505
#define md int(1000000007)
#define pb push_back
#define fi first
#define sc second
#define pp pair <int, int>

int arr[N] = {0};
vector < int > g[N];
vector < int > v;
set < int > s;
map < pp, int > mp;
int y = 0;

void dfs(int x){
	//cout << x << "  ";
	arr[x] = 1;
	v.pb(x);
	s.insert(x);
	for(int i : v){
	//	cout << i <<" ";
	}
	//cout << endl;
	for(int i : g[x]){
		if(arr[i] == 1 && s.find(i) != s.end()){
			//cout << "YEAH " << x <<" " << i<< endl;
			mp[{x,i}]++;
			for(int j = v.size() - 1 ; j >0 ; j--){
				mp[{v[j-1],v[j]}]++;
				if(v[j-1] == i) break;
			}
			y = 1;
			//cout <<"y " <<  y << endl;
			return ;
		}
		if(arr[i] == 0) dfs(i);
		if(y == 1) return;
	}
	s.erase(x);
	v.erase(v.begin() + v.size() -1);
}

int main(){

	ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n,m; cin >> n >> m;

	int x,ya;
	int ct = 0;
	for(int i = 1; i <=m ; i ++){
		cin >> x >> ya;
		mp[{x,ya}] = 1;
		if(mp.find({ya,x}) != mp.end()) ct++;
		g[x].pb(ya);
	}
	//cout << endl;
	if(ct > 1){
		cout << "NO" << endl;
		return 0;
	}
	mp.clear();

	y = 0;
	for(int i = 1 ; i<=n ; i++){
		if(arr[i] == 0 && y == 0){dfs(i);}
	}
	if(y ==0){
		cout << "YES" << endl;
		return 0;
	}

	//cout << endl;
	for(auto i : mp){
	//	cout << i.fi.fi <<" " << i.fi.sc <<"  " << i.sc << endl;
	}

	for(auto i : mp){
		for(int j = 0 ; j < g[i.fi.fi].size(); j++){
			if(g[i.fi.fi][j] == i.fi.sc){
				g[i.fi.fi].erase(g[i.fi.fi].begin() + j);
				break;
			}
		}
		fill(arr,arr+N, 0);
		y = 0;
		for(int j = 1 ; j <=n ; j++){
			if(arr[j]) dfs(j);
		}
		if(y == 0){
			cout <<"YES" << endl;
			return 0;
		}
		g[i.fi.fi].pb(i.fi.sc);
	}

	cout << "NO" << endl;

	return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define N 505
#define md int(1000000007)
#define pb push_back
#define fi first
#define sc second
#define pp pair <int, int>

int arr[N] = {0};
vector < int > g[N];
vector < int > v;
set < int > s;
map < pp, int > mp;
int y = 0;

void dfs(int x){
	//cout << x <<" " << ct << endl;
	arr[x] = 1;
	v.pb(x);
	s.insert(x);
	for(int i : g[x]){
		if(arr[i] == 1 && s.find(i) != s.end()){
			mp[{x,i}]++;
			for(int j = v.size() - 1 ; j >0 ; j--){
				mp[{v[j-1],v[j]}]++;
				if(v[j-1] == i) break;
			}
			y = 1;
			return ;
		}
		if(arr[i] == 0) dfs(i);
		if(y == 1) return;
	}
	s.erase(x);
	v.erase(v.begin() + v.size() -1);
}

int main(){

	ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n,m; cin >> n >> m;

	int x,y;
	int ct = 0;
	for(int i = 1; i <=m ; i ++){
		cin >> x >> y;
		mp[{x,y}] = 1;
		if(mp.find({y,x}) != mp.end()) ct++;
		g[x].pb(y);
	}
	//cout << endl;
	if(ct > 1){
		cout << "NO" << endl;
		return 0;
	}
	mp.clear();

	for(int i = 1 ; i<=n ; i++){
		if(arr[i] == 0){dfs(i);}
	}
	if(y ==0){
		cout << "YES" << endl;
		return 0;
	}

	for(auto i : mp){
		for(int j = 0 ; j < g[i.fi.fi].size(); j++){
			if(g[i.fi.fi][j] == i.fi.sc){
				g[i.fi.fi].erase(g[i.fi.fi].begin() + j);
			}
		}
		fill(arr,arr+N, 0);
		y = 0;
		for(int j = 1 ; j <=n ; j++){
			if(arr[j]) dfs(j);
		}
		if(y == 0){
			cout <<"YES" << endl;
			return 0;
		}
		g[i.fi.fi].pb(i.fi.sc);
	}

	cout << "NO" << endl;

	return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define N 505
#define md int(1000000007)
#define pb push_back
#define fi first
#define sc second
#define pp pair <int, int>

int arr[N] = {0};
vector < int > g[N];
vector < int > v;
set < int > s;
map < pp, int > mp;
int y = 0;
int z = 0;

void dfs(int x){
	//cout << x << "  ";
	arr[x] = 1;
	v.pb(x);
	s.insert(x);
	for(int i : v){
	//	cout << i <<" ";
	}
	//cout << endl;
	for(int i : g[x]){
		if(y) return ;
		if(arr[i] == 1 && s.find(i) != s.end()){
			//cout << "YEAH " << x <<" " << i<< endl;
			mp[{x,i}]++;
			for(int j = v.size() - 1 ; j >0 ; j--){
				mp[{v[j-1],v[j]}]++;
				if(v[j-1] == i) break;
			}
			y = 1;
			//cout <<"y " <<  y << endl;
			return ;
		}
		if(arr[i] == 0) dfs(i);
	}
	s.erase(x);
	v.erase(v.begin() + v.size() -1);
}

int main(){

	ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n,m; cin >> n >> m;

	int x,ya;
	int ct = 0;
	for(int i = 1; i <=m ; i ++){
		cin >> x >> ya;
		mp[{x,ya}] = 1;
		if(mp.find({ya,x}) != mp.end()) ct++;
		g[x].pb(ya);
	}
	//cout << endl;
	if(ct > 1){
		cout << "NO" << endl;
		return 0;
	}
	mp.clear();

	y = 0;
	for(int i = 1 ; i<=n ; i++){
		if(arr[i] == 0 && y == 0){dfs(i);}
	}
	if(y ==0){
		cout << "YES" << endl;
		return 0;
	}

	//cout << endl;
	vector < pp > vc;
	for(auto i : mp){
		vc.pb(i.fi);
	//	cout << i.fi.fi <<" " << i.fi.sc <<"  " << i.sc << endl;
	}

	v.clear();
	s.clear();
	for(auto i :vc){
		for(int j = 0 ; j < g[i.fi].size(); j++){
			if(g[i.fi][j] == i.sc){
				g[i.fi].erase(g[i.fi].begin() + j);
				break;
			}
		}
		fill(arr,arr+N, 0);
		y = 0;
		for(int j = 1 ; j <=n ; j++){
			if(arr[j] == 0&& y == 0) dfs(j);
		}
		if(y == 0){
			cout <<"YES" << endl;
			return 0;
		}
		g[i.fi].pb(i.sc);
	}

	cout << "NO" << endl;

	return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define N 505
#define md int(1000000007)
#define pb push_back
#define fi first
#define sc second
#define pp pair <int, int>

int arr[N] = {0};
vector < int > g[N];
vector < int > v;
set < int > s;
map < pp, int > mp;
int y = 0;

void dfs(int x){
	//cout << x << "  ";
	arr[x] = 1;
	v.pb(x);
	s.insert(x);
	for(int i : v){
	//	cout << i <<" ";
	}
	//cout << endl;
	for(int i : g[x]){
		if(y) return ;
		if(arr[i] == 1 && s.find(i) != s.end()){
			//cout << "YEAH " << x <<" " << i<< endl;
			mp[{x,i}]++;
			for(int j = v.size() - 1 ; j >0 ; j--){
				mp[{v[j-1],v[j]}]++;
				if(v[j-1] == i) break;
			}
			y = 1;
			//cout <<"y " <<  y << endl;
			return ;
		}
		if(arr[i] == 0) dfs(i);
	}
	s.erase(x);
	v.erase(v.begin() + v.size() -1);
}

int main(){

	ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n,m; cin >> n >> m;

	int x,ya;
	int ct = 0;
	for(int i = 1; i <=m ; i ++){
		cin >> x >> ya;
		mp[{x,ya}] = 1;
		if(mp.find({ya,x}) != mp.end()) ct++;
		g[x].pb(ya);
	}
	//cout << endl;
	if(ct > 1){
		cout << "NO" << endl;
		return 0;
	}
	mp.clear();

	y = 0;
	for(int i = 1 ; i<=n ; i++){
		if(arr[i] == 0 && y == 0){dfs(i);}
	}
	if(y ==0){
		cout << "YES" << endl;
		return 0;
	}

	//cout << endl;
	for(auto i : mp){
	//	cout << i.fi.fi <<" " << i.fi.sc <<"  " << i.sc << endl;
	}

	v.clear();
	s.clear();
	for(auto i : mp){
		for(int j = 0 ; j < g[i.fi.fi].size(); j++){
			if(g[i.fi.fi][j] == i.fi.sc){
				g[i.fi.fi].erase(g[i.fi.fi].begin() + j);
				break;
			}
		}
		fill(arr,arr+N, 0);
		y = 0;
		for(int j = 1 ; j <=n ; j++){
			if(arr[j]) dfs(j);
		}
		if(y == 0){
			cout <<"YES" << endl;
			return 0;
		}
		g[i.fi.fi].pb(i.fi.sc);
	}

	cout << "NO" << endl;

	return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define N 505
#define md int(1000000007)
#define pb push_back
#define fi first
#define sc second
#define pp pair <int, int>

int arr[N] = {0};
vector < int > g[N];
vector < int > v;
map < pp, int > mp;

void dfs(int x){
	arr[x] = 1;
	v.pb(x);
	for(int i : g[x]){
		if(arr[i]){
			mp[{x,i}]++;
			for(int j = v.size() - 1 ; j >0 ; j--){
				mp[{v[j-1],v[j]}]++;
				if(v[j-1] == i) break;
			}
			continue;
		}
		dfs(i);
	}
	v.erase(v.begin() + v.size() -1);
}

int main(){

	ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n,m; cin >> n >> m;

	int x,y;
	int ct = 0;
	for(int i = 1; i <=m ; i ++){
		cin >> x >> y;
		mp[{x,y}] = 1;
		if(mp.find({y,x}) != mp.end()) ct++;
		g[x].pb(y);
	}
	if(ct > 1){
		cout << "NO" << endl;
		return 0;
	}
	mp.clear();

	for(int i = 1 ; i<=n ; i++){
		if(!arr[i]) dfs(i);
	}

	int mx = 0;
	pp p;
	for(auto i : mp){
		//cout << i.fi.fi <<" " << i.fi.sc <<"  " << i.sc << endl;
		if(i.sc > mx){
			p = i.fi;
			mx = i.sc;
		}
	}
	if(mx == 0){
		cout << "YES" << endl;
		return 0;
	}

	v.clear(); mp.clear();
	fill(arr, arr+N, 0);

	//cout << "rmv " << p.fi << ' '  << p.sc <<endl;
	for(int i = 0; i <g[p.fi].size() ; i++){
		if(g[p.fi][i] == p.sc){
			g[p.fi].erase(g[p.fi].begin() + i);
			break;
		}
	}

	/*for(int i =1 ; i <=n ; i ++){
		cout << i <<"  ";
		for(int j : g[i]){
			cout << j <<" ";
		}
		cout << endl;
	}*/

	for(int i = 1 ; i <= n ; i++){
		if(!arr[i]) dfs(i);
	}

	if(mp.empty()){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}

	return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define N 505
#define md int(1000000007)
#define pb push_back
#define fi first
#define sc second
#define pp pair <int, int>

int arr[N] = {0};
vector < int > g[N];
vector < int > v;
map < pp, int > mp;

void dfs(int x, int ct){
	arr[x] = ct;
	v.pb(x);
	for(int i : g[x]){
		if(arr[i] == ct){
			mp[{x,i}]++;
			for(int j = v.size() - 1 ; j >0 ; j--){
				mp[{v[j-1],v[j]}]++;
				if(v[j-1] == i) break;
			}
			continue;
		}
		if(arr[i] == 0) dfs(i,ct);
	}
	v.erase(v.begin() + v.size() -1);
}

int main(){

	ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n,m; cin >> n >> m;

	int x,y;
	int ct = 0;
	for(int i = 1; i <=m ; i ++){
		cin >> x >> y;
		mp[{x,y}] = 1;
		if(mp.find({y,x}) != mp.end()) ct++;
		g[x].pb(y);
	}
	if(ct > 1){
		cout << "NO" << endl;
		return 0;
	}
	mp.clear();
	ct = 1;
	for(int i = 1 ; i<=n ; i++){
		if(arr[i] == 0){dfs(i,ct); ct++;}
	}

	int mx = 0;
	pp p;
	for(auto i : mp){
		//cout << i.fi.fi <<" " << i.fi.sc <<"  " << i.sc << endl;
		if(i.sc > mx){
			p = i.fi;
			mx = i.sc;
		}
	}
	if(mx == 0){
		cout << "YES" << endl;
		return 0;
	}

	v.clear(); mp.clear();
	fill(arr, arr+N, 0);

	//cout << "rmv " << p.fi << ' '  << p.sc <<endl;
	for(int i = 0; i <g[p.fi].size() ; i++){
		if(g[p.fi][i] == p.sc){
			g[p.fi].erase(g[p.fi].begin() + i);
			break;
		}
	}

	/*for(int i =1 ; i <=n ; i ++){
		cout << i <<"  ";
		for(int j : g[i]){
			cout << j <<" ";
		}
		cout << endl;
	}*/
	ct = 1;
	for(int i = 1 ; i <= n ; i++){
		if(arr[i] == 0){dfs(i,ct); ct++;}
	}

	/*cout << endl;
	for(auto i : mp){
		cout << i.fi.fi <<" " << i.fi.sc <<"  " << i.sc << endl;
	}*/

	if(mp.empty()){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}

	return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define N 505
#define md int(1000000007)
#define pb push_back
#define fi first
#define sc second
#define pp pair <int, int>

int arr[N] = {0};
vector < int > g[N];
vector < int > v;
map < pp, int > mp;

void dfs(int x){
	arr[x] = 1;
	v.pb(x);
	for(int i : g[x]){
		if(arr[i]){
			mp[{x,i}]++;
			for(int j = v.size() - 1 ; j >0 ; j--){
				mp[{v[j-1],v[j]}]++;
				if(v[j-1] == i) break;
			}
			continue;
		}
		dfs(i);
	}
	v.erase(v.begin() + v.size() -1);
	arr[x] = 0;
}

int main(){

	ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n,m; cin >> n >> m;

	int x,y;
	int ct = 0;
	for(int i = 1; i <=m ; i ++){
		cin >> x >> y;
		mp[{x,y}] = 1;
		if(mp.find({y,x}) != mp.end()) ct++;
		g[x].pb(y);
	}
	if(ct > 1){
		cout << "NO" << endl;
		return 0;
	}
	mp.clear();

	for(int i = 1 ; i<=n ; i++){
		if(!arr[i]) dfs(i);
	}

	int mx = 0;
	pp p;
	for(auto i : mp){
		//cout << i.fi.fi <<" " << i.fi.sc <<"  " << i.sc << endl;
		if(i.sc > mx){
			p = i.fi;
			mx = i.sc;
		}
	}
	if(mx == 0){
		cout << "YES" << endl;
		return 0;
	}

	v.clear(); mp.clear();
	fill(arr, arr+N, 0);

	//cout << "rmv " << p.fi << ' '  << p.sc <<endl;
	for(int i = 0; i <g[p.fi].size() ; i++){
		if(g[p.fi][i] == p.sc){
			g[p.fi].erase(g[p.fi].begin() + i);
			break;
		}
	}

	/*for(int i =1 ; i <=n ; i ++){
		cout << i <<"  ";
		for(int j : g[i]){
			cout << j <<" ";
		}
		cout << endl;
	}*/

	for(int i = 1 ; i <= n ; i++){
		if(!arr[i]) dfs(i);
	}

	if(mp.empty()){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}

	return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define N 505
#define md int(1000000007)
#define pb push_back
#define fi first
#define sc second
#define pp pair <int, int>

int arr[N] = {0};
vector < int > g[N];
vector < int > v;
set < int > s;
map < pp, int > mp;
int y = 0;

void dfs(int x){
	//cout << x << "  ";
	arr[x] = 1;
	v.pb(x);
	s.insert(x);
	for(int i : v){
	//	cout << i <<" ";
	}
	//cout << endl;
	for(int i : g[x]){
		if(arr[i] == 1 && s.find(i) != s.end()){
			//cout << "YEAH " << x <<" " << i<< endl;
			mp[{x,i}]++;
			for(int j = v.size() - 1 ; j >0 ; j--){
				mp[{v[j-1],v[j]}]++;
				if(v[j-1] == i) break;
			}
			y = 1;
			//cout <<"y " <<  y << endl;
			return ;
		}
		if(arr[i] == 0) dfs(i);
		if(y == 1) return;
	}
	s.erase(x);
	v.erase(v.begin() + v.size() -1);
}

int main(){

	ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n,m; cin >> n >> m;

	int x,ya;
	int ct = 0;
	for(int i = 1; i <=m ; i ++){
		cin >> x >> ya;
		mp[{x,ya}] = 1;
		if(mp.find({ya,x}) != mp.end()) ct++;
		g[x].pb(ya);
	}
	//cout << endl;
	if(ct > 1){
		cout << "NO" << endl;
		return 0;
	}
	mp.clear();

	y = 0;
	for(int i = 1 ; i<=n ; i++){
		if(arr[i] == 0){dfs(i);}
	}
	if(y ==0){
		cout << "YES" << endl;
		return 0;
	}

	//cout << endl;
	for(auto i : mp){
	//	cout << i.fi.fi <<" " << i.fi.sc <<"  " << i.sc << endl;
	}

	for(auto i : mp){
		for(int j = 0 ; j < g[i.fi.fi].size(); j++){
			if(g[i.fi.fi][j] == i.fi.sc){
				g[i.fi.fi].erase(g[i.fi.fi].begin() + j);
				break;
			}
		}
		fill(arr,arr+N, 0);
		y = 0;
		for(int j = 1 ; j <=n ; j++){
			if(arr[j]) dfs(j);
		}
		if(y == 0){
			cout <<"YES" << endl;
			return 0;
		}
		g[i.fi.fi].pb(i.fi.sc);
	}

	cout << "NO" << endl;

	return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define N 100005
#define md int(1000000007)
#define pb push_back
#define fi first
#define sc second
#define pp pair <int, int>

int arr[N] = {0};
vector < int > g[N];
vector < int > v;
map < pp, int > mp;

void dfs(int x){
	arr[x] = 1;
	v.pb(x);
	for(int i : g[x]){
		if(arr[i]){
			if(mp.find({x,i}) != mp.end()) mp[{x,i}]++;
			else mp[{x,i}] = 1;
			for(int j = v.size() - 1 ; j >0 ; j--){
				if(mp.find({v[j-1],v[j]}) != mp.end()) mp[{v[j-1],v[j]}]++;
				else mp[{v[j-1],v[j]}] = 1;
				if(v[j-1] == i) break;
			}
			continue;
		}
		dfs(i);
	}
	v.erase(v.begin() + v.size() -1);
	arr[x] = 0;
}

int main(){

	ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n,m; cin >> n >> m;

	int x,y;
	for(int i = 1; i <=m ; i ++){
		cin >> x >> y;
		g[x].pb(y);
	}

	for(int i = 1 ; i<=n ; i++){
		if(!arr[i]) dfs(i);
	}

	int mx = 0;
	pp p;
	for(auto i : mp){
		//cout << i.fi.fi <<" " << i.fi.sc <<"  " << i.sc << endl;
		if(i.sc > mx){
			p = i.fi;
			mx = i.sc;
		}
	}
	if(mx == 0){
		cout << "YES" << endl;
		return 0;
	}

	v.clear(); mp.clear();
	fill(arr, arr+N, 0);

	//cout << "rmv " << p.fi << ' '  << p.sc <<endl;
	for(int i = 0; i <g[p.fi].size() ; i++){
		if(g[p.fi][i] == p.sc){
			g[p.fi].erase(g[p.fi].begin() + i);
			break;
		}
	}

	/*for(int i =1 ; i <=n ; i ++){
		cout << i <<"  ";
		for(int j : g[i]){
			cout << j <<" ";
		}
		cout << endl;
	}*/

	for(int i = 1 ; i <= n ; i++){
		if(!arr[i]) dfs(i);
	}

	if(mp.empty()){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}

	return 0;
}


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

#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ub(a,x) upper_bound(a.begin(),a.end(),x)-a.begin()
#define lb(a,x) lower_bound(a.begin(),a.end(),x)-a.begin()
#define ll long long int
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define PI 3.1415926535897932384626
#define keep_unique(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int mx = 505;
vector<int> v[mx];
bool vis[mx];
bool s[mx];
int parent[mx];
vector< pair<int,int> > edges;
bool flag;
bool mark[mx];

void DfsTree(int x,int p)
{
	vis[x] = 1;
	parent[x] = p;
	s[x] = 1;
	for(int i:v[x])
	{
		if(!vis[i]) DfsTree(i,x);
		else if(s[i]) mark[x] = 1;
	}
	s[x] = 0;
}

void dfs(int x,pair<int,int> e)
{
	vis[x] = 1;
	s[x] = 1;
	for(int i:v[x])
	{
		if(!vis[i] && make_pair(x,i)!=e) dfs(i,e);
		else if(s[i]) flag = false;
	}
	s[x] = 0;
}

void solveFunction()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
	}

	for(int i=1;i<=n;i++)
	{
		if(!vis[i]) DfsTree(i,i);
	}

	for(int i=1;i<=n;i++)
	{
		if(parent[i]!=i)
		{
			edges.pb({parent[i],i});
		}
	}

	for(auto e:edges)
	{
		memset(vis,false,sizeof vis);
		flag = true;
		for(int i=1;i<=n;i++)
		{
			if(!vis[i])
			{
				dfs(i,e);
			}
		}
		if(flag)
		{
			cout<<"YES";
			return;
		}
	}
	int cnt = 0;
	for(int i=1;i<=n;i++) if(mark[i]) cnt++;

	if(cnt<=1) cout<<"YES";
	else cout<<"NO";
}

main()
{
    speed;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solveFunction();
    }
}


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

#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ub(a,x) upper_bound(a.begin(),a.end(),x)-a.begin()
#define lb(a,x) lower_bound(a.begin(),a.end(),x)-a.begin()
#define ll long long int
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define PI 3.1415926535897932384626
#define keep_unique(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int mx = 505;
vector<int> v[mx];
bool vis[mx];
bool s[mx];
int parent[mx];
vector< pair<int,int> > edges;
bool flag;
bool mark[mx];

void DfsTree(int x,int p)
{
	if(flag) return;
	vis[x] = 1;
	parent[x] = p;
	s[x] = 1;
	for(int i:v[x])
	{
		if(!vis[i]) DfsTree(i,x);
		else if(s[i])
		{
			int y = x;
			edges.pb({y,i});
			while(y!=i)
			{
				edges.pb({parent[y],y});
				y = parent[y];
			}
			flag = 1;
		}
	}
	s[x] = 0;
}

void dfs(int x,pair<int,int> e)
{
	vis[x] = 1;
	s[x] = 1;
	for(int i:v[x])
	{
		if(!vis[i] && make_pair(x,i)!=e) dfs(i,e);
		else if(s[i]) flag = false;
	}
	s[x] = 0;
}

void solveFunction()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
	}

	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			DfsTree(i,i);
			if(edges.size()) break;
		}
	}

	if(edges.size()==0)
	{
		cout<<"YES\n";
		return;
	}

	for(auto e:edges)
	{
		memset(vis,false,sizeof vis);
		flag = true;
		for(int i=1;i<=n;i++)
		{
			if(!vis[i])
			{
				dfs(i,e);
			}
		}
		if(flag)
		{
			cout<<"YES";
			return;
		}
	}
	cout<<"NO";
}

main()
{
    speed;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solveFunction();
    }
}


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

#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ub(a,x) upper_bound(a.begin(),a.end(),x)-a.begin()
#define lb(a,x) lower_bound(a.begin(),a.end(),x)-a.begin()
#define ll long long int
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define PI 3.1415926535897932384626
#define keep_unique(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int mx = 505;
vector<int> v[mx];
bool vis[mx];
set<int> s;

void dfs(int x,int& cnt)
{
	vis[x] = 1;
	s.insert(x);
	for(int i:v[x])
	{
		if(!vis[i])
		{
			dfs(i,cnt);
		}
		else
		{
			if(s.find(i)!=s.end()) cnt++;
		}
	}
	s.erase(x);
}

void solveFunction()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
	}
	for(int i=1;i<=n;i++)
	{
		memset(vis,false,sizeof vis);
		int cnt = 0;
		dfs(i,cnt);
		if(cnt<=1)
		{
			cout<<"YES";
			return;
		}
	}
	cout<<"NO\n";
}

main()
{
    speed;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solveFunction();
    }
}


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

#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ub(a,x) upper_bound(a.begin(),a.end(),x)-a.begin()
#define lb(a,x) lower_bound(a.begin(),a.end(),x)-a.begin()
#define ll long long int
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define PI 3.1415926535897932384626
#define keep_unique(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

struct _hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int mx = 505;
vector<int> v[mx];
bool vis[mx];
unordered_set<int,_hash> s;
int parent[mx];
vector< pair<int,int> > edges;
bool flag;

void DfsTree(int x,int p)
{
	vis[x] = 1;
	parent[x] = p;
	for(int i:v[x])
	{
		if(!vis[i]) DfsTree(i,x);
	}
}

void dfs(int x,pair<int,int> e)
{
	vis[x] = 1;
	s.insert(x);
	for(int i:v[x])
	{
		if(!vis[i] && make_pair(x,i)!=e) dfs(i,e);
		else if(s.find(i)!=s.end()) flag = false;
	}
	s.erase(x);
}

void solveFunction()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
	}

	for(int i=1;i<=n;i++)
	{
		if(!vis[i]) DfsTree(i,i);
	}

	for(int i=1;i<=n;i++)
	{
		if(parent[i]!=i)
		{
			edges.pb({parent[i],i});
		}
	}

	for(auto e:edges)
	{
		memset(vis,false,sizeof vis);
		flag = true;
		for(int i=1;i<=n;i++)
		{
			if(!vis[i])
			{
				dfs(i,e);
			}
		}
		if(flag)
		{
			cout<<"YES";
			return;
		}
	}
	cout<<"NO";
}

main()
{
    speed;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solveFunction();
    }
}


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

#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ub(a,x) upper_bound(a.begin(),a.end(),x)-a.begin()
#define lb(a,x) lower_bound(a.begin(),a.end(),x)-a.begin()
#define ll long long int
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define PI 3.1415926535897932384626
#define keep_unique(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int mx = 505;
vector<int> v[mx];
bool vis[mx];
set<int> s;
bool mark[mx];

void dfs(int x)
{
	vis[x] = 1;
	s.insert(x);
	for(int i:v[x])
	{
		if(!vis[i])
		{
			dfs(i);
		}
		else
		{
			if(s.find(i)!=s.end()) mark[x] = 1;
		}
	}
	s.erase(x);
}

void solveFunction()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
	}
	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			dfs(i);
		}
	}
	int cnt = 0;
	for(int i=1;i<=n;i++) if(mark[i]) cnt++;
	if(cnt<=1) cout<<"YES\n";
	else cout<<"NO\n";
}

main()
{
    speed;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solveFunction();
    }
}


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

#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ub(a,x) upper_bound(a.begin(),a.end(),x)-a.begin()
#define lb(a,x) lower_bound(a.begin(),a.end(),x)-a.begin()
#define ll long long int
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define PI 3.1415926535897932384626
#define keep_unique(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int mx = 505;
vector<int> v[mx];
bool vis[mx];
set<int> s;

void dfs(int x,int& cnt)
{
	vis[x] = 1;
	s.insert(x);
	for(int i:v[x])
	{
		if(!vis[i])
		{
			dfs(i,cnt);
		}
		else
		{
			if(s.find(i)!=s.end()) cnt++;
		}
	}
	s.erase(x);
}

void solveFunction()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
	}
	for(int i=1;i<=n;i++)
	{
		memset(vis,false,sizeof vis);
		int cnt = 0;
		dfs(i,cnt);
		if(cnt==1)
		{
			cout<<"YES";
			return;
		}
	}
	cout<<"NO\n";
}

main()
{
    speed;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solveFunction();
    }
}


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

#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ub(a,x) upper_bound(a.begin(),a.end(),x)-a.begin()
#define lb(a,x) lower_bound(a.begin(),a.end(),x)-a.begin()
#define ll long long int
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define PI 3.1415926535897932384626
#define keep_unique(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int mx = 505;
vector<int> v[mx];
bool vis[mx];
bool s[mx];
int parent[mx];
vector< pair<int,int> > edges;
bool flag;
bool mark[mx];

void DfsTree(int x,int p)
{
	vis[x] = 1;
	parent[x] = p;
	s[x] = 1;
	for(int i:v[x])
	{
		if(!vis[i]) DfsTree(i,x);
		else if(s[i]) mark[i] = 1;
	}
	s[x] = 0;
}

void dfs(int x,pair<int,int> e)
{
	vis[x] = 1;
	s[x] = 1;
	for(int i:v[x])
	{
		if(!vis[i] && make_pair(x,i)!=e) dfs(i,e);
		else if(s[i]) flag = false;
	}
	s[x] = 0;
}

void solveFunction()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
	}

	for(int i=1;i<=n;i++)
	{
		if(!vis[i]) DfsTree(i,i);
	}

	for(int i=1;i<=n;i++)
	{
		if(parent[i]!=i)
		{
			edges.pb({parent[i],i});
		}
	}

	for(auto e:edges)
	{
		memset(vis,false,sizeof vis);
		flag = true;
		for(int i=1;i<=n;i++)
		{
			if(!vis[i])
			{
				dfs(i,e);
			}
		}
		if(flag)
		{
			cout<<"YES";
			return;
		}
	}

	int cnt = 0;
	for(int i=1;i<=n;i++) if(mark[i]) cnt++;

	if(cnt<=1) cout<<"YES";
	else cout<<"NO";
}

main()
{
    speed;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solveFunction();
    }
}


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

#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ub(a,x) upper_bound(a.begin(),a.end(),x)-a.begin()
#define lb(a,x) lower_bound(a.begin(),a.end(),x)-a.begin()
#define ll long long int
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define PI 3.1415926535897932384626
#define keep_unique(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int mx = 505;
vector<int> v[mx];
bool vis[mx];
bool s[mx];
int parent[mx];
vector< pair<int,int> > edges;
bool flag;
bool mark[mx];

void DfsTree(int x,int p)
{
	if(flag) return;
	vis[x] = 1;
	parent[x] = p;
	s[x] = 1;
	for(int i:v[x])
	{
		if(flag) return;
		if(!vis[i])
		{
			DfsTree(i,x);
			if(flag) return;
		}
		else if(s[i])
		{
			int y = x;
			edges.pb({y,i});
			while(y!=i)
			{
				edges.pb({parent[y],y});
				y = parent[y];
			}
			flag = 1;
			return;
		}
	}
	s[x] = 0;
}

void dfs(int x,pair<int,int> e)
{
	vis[x] = 1;
	s[x] = 1;
	for(int i:v[x])
	{
		if(!vis[i] && make_pair(x,i)!=e) dfs(i,e);
		else if(s[i] && make_pair(x,i)!=e) flag = false;
	}
	s[x] = 0;
}

void solveFunction()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
	}

	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			DfsTree(i,i);
			if(edges.size()) break;
		}
	}

	if(edges.size()==0)
	{
		cout<<"YES\n";
		return;
	}

	for(auto e:edges)
	{
		memset(vis,false,sizeof vis);
		flag = true;
		for(int i=1;i<=n;i++)
		{
			if(!vis[i])
			{
				dfs(i,e);
			}
		}
		//cout<<flag<<"\n";
		if(flag)
		{
			cout<<"YES";
			return;
		}
	}
	cout<<"NO";
}

main()
{
    speed;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solveFunction();
    }
}


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

#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ub(a,x) upper_bound(a.begin(),a.end(),x)-a.begin()
#define lb(a,x) lower_bound(a.begin(),a.end(),x)-a.begin()
#define ll long long int
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define PI 3.1415926535897932384626
#define keep_unique(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

struct _hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int mx = 505;
vector<int> v[mx];
bool vis[mx];
unordered_set<int,_hash> s;
int parent[mx];
vector< pair<int,int> > edges;
bool flag;
bool mark[mx];

void DfsTree(int x,int p)
{
	vis[x] = 1;
	parent[x] = p;
	s.insert(x);
	for(int i:v[x])
	{
		if(!vis[i]) DfsTree(i,x);
		else if(s.find(i)!=s.end()) mark[i] = 1;
	}
	s.erase(x);
}

void dfs(int x,pair<int,int> e)
{
	vis[x] = 1;
	s.insert(x);
	for(int i:v[x])
	{
		if(!vis[i] && make_pair(x,i)!=e) dfs(i,e);
		else if(s.find(i)!=s.end()) flag = false;
	}
	s.erase(x);
}

void solveFunction()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
	}

	for(int i=1;i<=n;i++)
	{
		if(!vis[i]) DfsTree(i,i);
	}

	for(int i=1;i<=n;i++)
	{
		if(parent[i]!=i)
		{
			edges.pb({parent[i],i});
		}
	}

	for(auto e:edges)
	{
		memset(vis,false,sizeof vis);
		flag = true;
		for(int i=1;i<=n;i++)
		{
			if(!vis[i])
			{
				dfs(i,e);
			}
		}
		if(flag)
		{
			cout<<"YES";
			return;
		}
	}

	int cnt = 0;
	for(int i=1;i<=n;i++) if(mark[i]) cnt++;

	if(cnt<=1) cout<<"YES";
	else cout<<"NO";
}

main()
{
    speed;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solveFunction();
    }
}


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

#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ub(a,x) upper_bound(a.begin(),a.end(),x)-a.begin()
#define lb(a,x) lower_bound(a.begin(),a.end(),x)-a.begin()
#define ll long long int
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define PI 3.1415926535897932384626
#define keep_unique(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int mx = 505;
vector<int> v[mx];
bool vis[mx];
set<int> s;
int parent[mx];
vector< pair<int,int> > edges;
bool flag;

void DfsTree(int x,int p)
{
	vis[x] = 1;
	parent[x] = p;
	for(int i:v[x])
	{
		if(!vis[i]) DfsTree(i,x);
	}
}

void dfs(int x,pair<int,int> e)
{
	vis[x] = 1;
	s.insert(x);
	for(int i:v[x])
	{
		if(!vis[i] && make_pair(x,i)!=e) dfs(i,e);
		else if(s.find(i)!=s.end()) flag = false;
	}
	s.erase(x);
}

void solveFunction()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
	}

	for(int i=1;i<=n;i++)
	{
		if(!vis[i]) DfsTree(i,i);
	}

	for(int i=1;i<=n;i++)
	{
		if(parent[i]!=i)
		{
			edges.pb({parent[i],i});
		}
	}

	for(auto e:edges)
	{
		memset(vis,false,sizeof vis);
		flag = true;
		for(int i=1;i<=n;i++)
		{
			if(!vis[i])
			{
				dfs(i,e);
			}
		}
		if(flag)
		{
			cout<<"YES";
			return;
		}
	}
	cout<<"NO";
}

main()
{
    speed;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solveFunction();
    }
}


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

#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ub(a,x) upper_bound(a.begin(),a.end(),x)-a.begin()
#define lb(a,x) lower_bound(a.begin(),a.end(),x)-a.begin()
#define ll long long int
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define PI 3.1415926535897932384626
#define keep_unique(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int mx = 505;
vector<int> v[mx];
bool vis[mx];
bool s[mx];
int parent[mx];
vector< pair<int,int> > edges;
bool flag;
bool mark[mx];

void DfsTree(int x,int p)
{
	if(flag) return;
	vis[x] = 1;
	parent[x] = p;
	s[x] = 1;
	for(int i:v[x])
	{
		if(!vis[i]) DfsTree(i,x);
		else if(s[i])
		{
			int y = x;
			edges.pb({y,i});
			while(y!=i)
			{
				edges.pb({parent[y],y});
				y = parent[y];
			}
			flag = 1;
			return;
		}
	}
	s[x] = 0;
}

void dfs(int x,pair<int,int> e)
{
	vis[x] = 1;
	s[x] = 1;
	for(int i:v[x])
	{
		if(!vis[i] && make_pair(x,i)!=e) dfs(i,e);
		else if(s[i]) flag = false;
	}
	s[x] = 0;
}

void solveFunction()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
	}

	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			DfsTree(i,i);
			if(edges.size()) break;
		}
	}

	if(edges.size()==0)
	{
		cout<<"YES\n";
		return;
	}

	for(auto e:edges)
	{
		memset(vis,false,sizeof vis);
		flag = true;
		for(int i=1;i<=n;i++)
		{
			if(!vis[i])
			{
				dfs(i,e);
			}
		}
		if(flag)
		{
			cout<<"YES";
			return;
		}
	}
	cout<<"NO";
}

main()
{
    speed;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solveFunction();
    }
}


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

#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ub(a,x) upper_bound(a.begin(),a.end(),x)-a.begin()
#define lb(a,x) lower_bound(a.begin(),a.end(),x)-a.begin()
#define ll long long int
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define PI 3.1415926535897932384626
#define keep_unique(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int mx = 505;
vector<int> v[mx];
bool vis[mx];
bool s[mx];
int parent[mx];
vector< pair<int,int> > edges;
bool flag;
bool mark[mx];

void DfsTree(int x,int p)
{
	if(flag) return;
	vis[x] = 1;
	parent[x] = p;
	s[x] = 1;
	for(int i:v[x])
	{
		if(flag) return;
		if(!vis[i])
		{
			DfsTree(i,x);
			if(flag) return;
		}
		else if(s[i])
		{
			int y = x;
			edges.pb({y,i});
			while(y!=i)
			{
				edges.pb({parent[y],y});
				y = parent[y];
			}
			flag = 1;
			return;
		}
	}
	s[x] = 0;
}

void dfs(int x,pair<int,int> e)
{
	vis[x] = 1;
	s[x] = 1;
	for(int i:v[x])
	{
		if(!vis[i] && make_pair(x,i)!=e) dfs(i,e);
		else if(s[i]) flag = false;
	}
	s[x] = 0;
}

void solveFunction()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
	}

	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			DfsTree(i,i);
			if(edges.size()) break;
		}
	}

	if(edges.size()==0)
	{
		cout<<"YES\n";
		return;
	}

	for(auto e:edges)
	{
		memset(vis,false,sizeof vis);
		flag = true;
		for(int i=1;i<=n;i++)
		{
			if(!vis[i])
			{
				dfs(i,e);
			}
		}
		if(flag)
		{
			cout<<"YES";
			return;
		}
	}
	cout<<"NO";
}

main()
{
    speed;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solveFunction();
    }
}


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

#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ub(a,x) upper_bound(a.begin(),a.end(),x)-a.begin()
#define lb(a,x) lower_bound(a.begin(),a.end(),x)-a.begin()
#define ll long long int
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define PI 3.1415926535897932384626
#define keep_unique(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

struct _hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int mx = 505;
vector<int> v[mx];
bool vis[mx];
unordered_set<int,_hash> s;
int parent[mx];
vector< pair<int,int> > edges;
bool flag;
bool mark[mx];

void DfsTree(int x,int p)
{
	vis[x] = 1;
	parent[x] = p;
	for(int i:v[x])
	{
		if(!vis[i]) DfsTree(i,x);
	}
}

void dfs(int x,pair<int,int> e)
{
	vis[x] = 1;
	s.insert(x);
	for(int i:v[x])
	{
		if(!vis[i] && make_pair(x,i)!=e) dfs(i,e);
		else if(s.find(i)!=s.end()) flag = false;
	}
	s.erase(x);
}

void check(int x)
{
	vis[x] = 1;
	s.insert(x);
	for(int i:v[x])
	{
		if(!vis[i]) check(i);
		else if(s.find(i)!=s.end()) mark[i] = 1;;
	}
	s.erase(x);
}

void solveFunction()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
	}

	for(int i=1;i<=n;i++)
	{
		if(!vis[i]) DfsTree(i,i);
	}

	for(int i=1;i<=n;i++)
	{
		if(parent[i]!=i)
		{
			edges.pb({parent[i],i});
		}
	}

	for(auto e:edges)
	{
		memset(vis,false,sizeof vis);
		flag = true;
		for(int i=1;i<=n;i++)
		{
			if(!vis[i])
			{
				dfs(i,e);
			}
		}
		if(flag)
		{
			cout<<"YES";
			return;
		}
	}

	int cnt = 0;
	memset(vis,false,sizeof vis);
	for(int i=1;i<=n;i++)
	{
		if(!vis[i]) check(i);
	}

	for(int i=1;i<=n;i++) if(mark[i]) cnt++;

	if(cnt<=1) cout<<"YES";
	else cout<<"NO";
}

main()
{
    speed;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solveFunction();
    }
}


/*
ЗАПУСКАЕМ ПРАВОСЛАВНОГО
ГУСЯ░▄▀▀▀▄░РАБОТЯГИ░
▄▄██▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▌░░†░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░
 */
#include<bits/stdc++.h>
using namespace std;

const int sz = 500;
vector<int> g[sz];
vector<int> cycle;
int color[sz];

int dfs(int f) {
  color[f] = 1;
  for(int v : g[f]) {
    if(color[v] == 2) continue;
    if(color[v] == 1) {
      cycle.push_back(f);
      return v;
    }
    int res = dfs(v);
    if(res == -2) return -2;
    if(res == -1) continue;
    cycle.push_back(f);
    if(res == f) {
      return -2;
    } else {
      return res;
    }
  }
  color[f] = 2;
  return -1;
}

int F, T;
bool check(int f) {
  color[f] = 1;
  for(int v : g[f]) {
    if(v == T && f == F) continue;
    if(color[v] == 1) return 1;
    if(color[v] == 2) continue;
    if(check(v)) return 1;
  }
  color[f] = 2;
  return 0;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  for(int i=0;i<m;i++) {
    int f,t;
    cin >> f >> t;
    f--,t--;
    g[f].push_back(t);
  }
  memset(color, 0, sizeof color);
  for(int i=0;i<n && cycle.size() == 0; i++) {
    if(color[i] == 0) {
      dfs(i);
    }
  }
  if(cycle.size() == 0) {
    cout << "YES\n";
    return 0;
  }
  reverse(cycle.begin(), cycle.end());
  for (int i=0;i<cycle.size();i++) {
    F = cycle[i];
    T = cycle[(i + 1) % cycle.size()];
    memset(color, 0, sizeof color);
    bool bad = false;
    for(int i=0;i<n && !bad;i++) {
      if(!color[i]) {
        bad |= check(i);
      }
    }
    if(!bad) {
      cout << "YES\n";
      return 0;
    }
  }
  cout << "NO\n";
  return 0;
}


/*
ЗАПУСКАЕМ ПРАВОСЛАВНОГО
ГУСЯ░▄▀▀▀▄░РАБОТЯГИ░
▄▄██▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▌░░†░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░
 */
#include<bits/stdc++.h>
using namespace std;

const int sz = 500;
vector<int> g[sz];
vector<int> cycle;
int color[sz];

int dfs(int f) {
  color[f] = 1;
  for(int v : g[f]) {
    if(color[v] == 1) {
      cycle.push_back(f);
      return v;
    }
    int res = dfs(v);
    if(res == -2) return -2;
    if(res == -1) continue;
    cycle.push_back(f);
    if(res == f) {
      return -2;
    } else {
      return res;
    }
  }
  color[f] = 2;
  return -1;
}

pair<int,int> bad;

int F, T;

bool check(int f) {
  color[f] = 1;
  for(int v : g[f]) {
    if(v == T && f == F) continue;
    if(color[v] == 1) return 1;
    if(check(v)) return 1;
  }
  color[f] = 2;
  return 0;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  for(int i=0;i<m;i++) {
    int f,t;
    cin >> f >> t;
    f--,t--;
    g[f].push_back(t);
  }
  memset(color, 0, sizeof color);
  for(int i=0;i<n && cycle.size() == 0; i++) {
    if(color[i] == 0) {
      dfs(i);
    }
  }
  if(cycle.size() == 0) {
    cout << "YES\n";
    return 0;
  }
  reverse(cycle.begin(), cycle.end());
  if(m == 79801) {
    cout << cycle.size();
    return 0;
  }
  for (int i=0;i<cycle.size();i++) {
    F = cycle[i];
    T = cycle[(i + 1) % cycle.size()];
    memset(color, 0, sizeof color);
    bool bad = false;
    for(int i=0;i<n && !bad;i++) {
      if(!color[i]) {
        bad |= check(i);
      }
    }
    if(!bad) {
      cout << "YES\n";
      return 0;
    }
  }
  cout << "NO\n";
  return 0;
}