#include <cstdio>
#include <list>
#include <vector>
#include <queue>
#include <cstring>
#include <cstdlib>
using namespace std;
const int MAXN = 10000;
const int MAXM = 20000;
class Graph
{
static const int MAX_VERTICES = MAXN * 2 + 2;
static const int MAX_CAPACITY = (int)1;
static const int MAX_EDGES = MAXM + MAXN * 2;
struct edge_t
{
int to;
int flow, capacity;
int residual_capacity()const { return capacity - flow; }
};
static edge_t edges[2*MAX_EDGES];
int edges_size;
static vector<int> out_edges[MAX_VERTICES];
static int first[MAX_VERTICES];
static int dist[MAX_VERTICES];
int source, sink, vertices;
bool build_level_graph()
{
memset(dist, -1, sizeof(*dist) * vertices);
static int q[MAX_VERTICES];
int q_head = 0, q_tail = 0;
dist[source] = 0;
q[q_tail++] = source;
while (q_head < q_tail && dist[sink] == -1)
{
int vertex = q[q_head++];
for (int edge : out_edges[vertex])
{
const edge_t &forward = edges[edge];
if (dist[forward.to] == -1 && forward.residual_capacity() > 0)
{
q[q_tail++] = forward.to;
dist[forward.to] = dist[vertex] + 1;
}
}
}
return dist[sink] != -1;
}
int find_blocking_flow(int vertex, int flow)
{
if (flow == 0)
{
return 0;
}
if (vertex == sink)
{
return flow;
}
for (; first[vertex] < (int)out_edges[vertex].size(); ++first[vertex])
{
edge_t &forward = edges[out_edges[vertex][first[vertex]]];
if (dist[forward.to] == dist[vertex] + 1)
{
int augumenting = find_blocking_flow(forward.to, min(flow, forward.residual_capacity()));
if (augumenting > 0)
{
edge_t &backward = edges[out_edges[vertex][first[vertex]] ^ 1];
forward.flow += augumenting;
backward.flow -= augumenting;
return augumenting;
}
}
}
return false;
}
public:
Graph(int vertices, int source, int sink) : vertices(vertices), source(source), sink(sink), edges_size(0)
{}
void add_edge(int from, int to, int capacity)
{
edge_t forward = { to, 0, capacity };
edge_t backward = { from, 0, 0 };
out_edges[from].push_back(edges_size);
edges[edges_size++] = forward;
out_edges[to].push_back(edges_size);
edges[edges_size++] = backward;
}
long long max_flow()
{
long long answer = 0;
for (int i = 0; build_level_graph(); ++i)
{
memset(first, 0, sizeof(*first)*vertices);
int augmenting = find_blocking_flow(source, MAX_CAPACITY);
if (augmenting > 0)
{
answer += augmenting;
}
else
{
break;
}
}
return answer;
}
};
Graph::edge_t Graph::edges[2*Graph::MAX_EDGES] = {};
vector<int> Graph::out_edges[Graph::MAX_VERTICES] = {};
int Graph::first[Graph::MAX_VERTICES] = {};
int Graph::dist[Graph::MAX_VERTICES] = {};
void _1711()
{
int n, m;
scanf("%d%d", &n, &m);
Graph graph(n, 0, n-1);
for (int i = 0; i < m; ++i)
{
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
--a; --b;
graph.add_edge(a, b, c);
}
printf("%lld\n", graph.max_flow());
exit(0);
}
int main()
{
int n, m;
//_1711();
while (2 == scanf("%d%d", &n, &m))
{
Graph graph(2*n + 2, 0, 2*n + 1);
for (int person = 1; person <= n; ++person)
{
graph.add_edge(0, person, 1);
graph.add_edge(person+n, 2*n+1, 1);
}
for (int interest = 0; interest < m; ++interest)
{
int a, b;
scanf("%d%d", &a, &b);
++a; ++b;
graph.add_edge(a, n + b, 1);
}
if (graph.max_flow() == n)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGxpc3Q+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxxdWV1ZT4KI2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDxjc3RkbGliPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNvbnN0IGludCBNQVhOID0gMTAwMDA7CmNvbnN0IGludCBNQVhNID0gMjAwMDA7CgpjbGFzcyBHcmFwaAp7CglzdGF0aWMgY29uc3QgaW50IE1BWF9WRVJUSUNFUyA9IE1BWE4gKiAyICsgMjsKCXN0YXRpYyBjb25zdCBpbnQgTUFYX0NBUEFDSVRZID0gKGludCkxOwoJc3RhdGljIGNvbnN0IGludCBNQVhfRURHRVMgPSBNQVhNICsgTUFYT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