/***************************************************DarkdreamOFmy**********************************************************/
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <assert.h>
#include <time.h>
#include <fstream>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

typedef                                     long int li;
typedef                                     long long int lli;
typedef                                     unsigned long long int ull;
typedef                                     signed long long int sll;
typedef                                     long double lld;
typedef                                     vector<int>vi;
typedef                                     vector<long>vl;
typedef                                     vector<long long int>vll;
typedef                                     vector<double>vd;
typedef                                     vector<long double>vld;
typedef                                     vector<char>vc;
typedef                                     vector<string>vs;
typedef                                     pair<int,int>pii;
typedef                                     pair<long long,long long>pll;
typedef                                     pair<double,double>pdd;
typedef                                     pair<char,char>pcc;
typedef                                     pair<string,string>pss;
typedef                                     map<int,int>mii;
typedef                                     map<long long,long long>mll;
typedef                                     map<char,char>mcc;
typedef                                     map<string,string>mss;
typedef                                     map<string,int>msi;
typedef                                     map< int,vector<int> >miv;
typedef                                     map<vector<int>,vector<int> >mvvi;
typedef                                     map<string,vector<int> >msv;
typedef                                     set<int>si;
typedef                                     set<string>ss;
typedef                                     set<vector<int> >sv;
typedef                                     queue<int>qi;
typedef                                     queue<long long>qll;
typedef                                     queue<string>qs;
typedef                                     stack<int>stki;
typedef                                     stack<long long>stkll;

/**-------------------END OF typedef------------------------------**/

const int                                   INF  = 1000000000;
const int                                   MAX  = 4007;
const int                                   MAX2 = 1000000;
const int                                   MAXD = 20;
const int                                   BASE = 1000000007;
const int                                   MOD  = 1000000007;
const int                                   psz  = 2000006;

/**-------------------Constant int--------------------------------**/

#define sI(a)                               scanf("%d",&a)
#define sI2(a,b)                            sI(a) , sI(b)
#define sI3(a,b,c)                          sI(a), sI(b), sI(c)
#define sI4(a,b,c,d)                        sI(a), sI(b), sI(c), sI(d)

#define sL(a)                               scanf("%lld",&a)
#define sL2(a,b)                            sL(a) , sL(b)
#define sL3(a,b,c)                          sL(a), sL(b), sL(c)
#define sL4(a,b,c,d)                        sL(a), sL(b), sL(c), sL(d)

#define pI(a)                               printf("%d",a)
#define pI2(a,b)                            pI(a) , pI(b)
#define pI3(a,b,c)                          pI(a), pI(b), pI(c)
#define pI4(a,b,c,d)                        pI(a), pI(b), pI(c), pI(d)

#define pL(a)                               printf("%lld",a)
#define pL2(a,b)                            pL(a) , pL(b)
#define pL3(a,b,c)                          pL(a), pL(b), pL(c)
#define pL4(a,b,c,d)                        pL(a), pL(b), pL(c), pL(d)

/**----------------------Scan and print end--------------------------**/

#define min3(a,b,c)                         min(a,min(b,c))
#define max3(a,b,c)                         max(a,max(b,c))
#define min4(a,b,c,d)                       min(min(a,b),min(c,d))
#define max4(a,b,c,d)                       max(max(a,b),max(c,d))
#define max5(a,b,c,d,e)                     max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e)                     min(min3(a,b,c),min(d,e))

/**----------------------MAX and MIN end-----------------------------**/

#define fst                                 first
#define snd                                 second
#define all(a)                              a.begin(),a.end()
#define rall(a)                             a.rbegin(),a.rend()
#define SQR(a)                              ((a)*(a))
#define Unique(a)                           sort(all(a)),a.erase(unique(all(a)),a.end())
#define Iterator(a)                         __typeof__(a.begin())
#define rIterator(a)                        __typeof__(a.rbegin())
#define FORI(a,it)                          for(Iterator(a) it = a.begin();it != a.end(); it++)
#define RFORI(a,it)                         for(rIterator(a) it = a.rbegin();it != a.rend(); it++)
#define FOR(i, a, b)                        for(int i=(a);i<(b);i++)
#define RFOR(i, b, a)                       for(int i=(b)-1;i>=(a);--i)
#define FILL(A,value)                       memset(A,value,sizeof(A))
#define SZ(V)                               (int)V.size()
#define PB                                  push_back
#define MP                                  make_pair
#define Pi                                  3.14159265358979
#define read(x)                             freopen(x, "r", stdin)
#define write(x)                            freopen(x, "w", stdout)

/**---------------------End of define of all----------------------**/

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};

int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};

/**-----------------------Directional------------------------------**/

inline int number_of_edges(int degreeofvertices)   {int res; res=(degreeofvertices)/2;return res;};
inline int josephus(int n,int k)                   {if(n==1){return 1;}else{return (josephus(n-1,k)+k-1)%n+1;}}

/**-----------------------Normal equations-------------------------**/

inline int binary_src(int a[],int n,int k)         {int lo=0,hi=n-1,mid;while(lo<=hi){mid=(lo+hi)/2;if(a[mid]==k){return mid+1;}else if(a[mid]>k){hi=mid-1;}else if(a[mid]<k){lo=mid+1;}}return -1;}
inline bool isLeap(lli y)                          {return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false); }
inline int chToIn(char a)                          {int b;b = a-'0';return b;}
inline char inTOch(int a)                          {char b;b= a+'0';return b;}
inline int stToIn(string a)                        {int b;b=atoi(a.c_str());return b;}
inline string appendChar(string s,char a)          {s.append(1,a);return s;}
inline string rev(string a)                        {int siz=SZ(a);string res="";RFOR(i,siz,0){res+=a[i];}return res;}
inline int gcd(int a, int b)                       {return (b == 0 ? a : gcd(b, a % b));}
inline int lcm(int a, int b)                       {return (a * (b / gcd(a, b))); }
vll factors_n; inline lli factor_find_n(lli n)     {for(lli i=2; i<=n; i++)while(n%i==0){n/=i; factors_n.PB(i);}}
vll factors_sqr; inline lli factor_find_sqrt(lli n){for(lli i=2; i*i<=n; i++)while(n%i==0){n/=i; factors_sqr.PB(i);}}
inline lli bigmod(lli a,lli b,lli m)               {if(b==0)return 1%m;lli x=bigmod(a,b/2,m);x=(x*x)%m;if(b%2==1){x=(x*a)%m;}return x;}
inline lli phi(lli n)                              {lli ret=n;for(lli i=2; i*i<=n; i++){if(n%i==0){while(n%i==0)n/=i;}ret-=ret/i;}if(n>1){ret-=ret/n;}return ret;}

/**---------------------End of functions--------------------------**/

int main(){
    lli n,k;
    sL2(n,k);
    lli sum=0;
    lli mn=INF*2;
    lli a[n+10];
    FOR(i,0,n){
        sL(a[i]);
        mn=min(a[i],mn);
    }
    FOR(i,0,n){
        sum+=abs(mn-a[i]);
    }
    lli res=sum/k;
    if(sum%k==0){
        pL(res);
    }
    else{
        res=-1;
        pL(res);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define N 1e9+9
long long ar[1000009];
int main()
{
    long long n,m,i,mn,f,sum;

    while(cin>>n>>m)
    {
        mn=N;
        f=0;
        for(i=0;i<n;i++)
        {
            cin>>ar[i];
            mn=min(mn,ar[i]);
            if(ar[i]%m!=0)
                f=1;
        }
        if(f==1)
            cout<<-1<<endl;
        else{
                sum=0;
            for(i=0;i<n;i++)
            {
                sum+=(ar[i]-mn)/m;
            }
        cout<<sum<<endl;
        }
    }
    return 0;
}


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.ObjectInputStream.GetField;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.SortedSet;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;

public class Q21 {
	static int MOD = 1000000007;
	static boolean b[],b1[], c1 = false;
	static int m, bo, c, di;
	static ArrayList<Integer>[] amp;
	static ArrayList<Integer>[][] amp2;
	static long sum[], dist[], arr[], cnt[];
	static long pow[], ans = 0;
	static int p = 10000, time = 0, p1 = -1, p2 = -1;
	static FasterScanner sc = new FasterScanner();
	static Queue<Integer> q = new LinkedList<>();
	static ArrayList<Pair>[] amp1;
	static int arr1[];
	static ArrayList<Integer> parent = new ArrayList<>();
	static BufferedWriter log;
	static HashMap<Pair, Integer> hm;
	static HashSet<Integer> hs = new HashSet<>();
	static TreeMap<Integer, Pair> hsm;
	static Stack<Integer> s = new Stack<>();
	static Pair prr[];
	static Random r = new Random();
	static long dp[];
	static int MAX = (int) 1e7;
	public static void main(String[] args) throws IOException {
		log = new BufferedWriter(new OutputStreamWriter(System.out));
		int n = sc.nextInt(), m = sc.nextInt();
		amp = (ArrayList<Integer>[]) new ArrayList[n];
		for(int i = 0; i< n; i++) amp[i] =new ArrayList<>();
		buildGraph(m);
		b = new boolean[n];
		for(int i = 0 ;i<n;i++){
			if(!b[i] && amp[i].size()>1){
				ans = 0;p = 0;
				bfs(i);
				//System.out.println(ans+" "+p);
				if(ans != (1L*p*(p-1))){
					System.out.println("NO");return;
				}
			}
		}
		System.out.println("YES");
		log.close();
	}

	public static void bfs(int x) {
		b[x] = true;
		q = new LinkedList<Integer>();
		q.add(x);
		while (!q.isEmpty()) {
			int y = q.poll();
			p++;
			ans+=amp[y].size();
			for (int i = 0; i < amp[y].size(); i++) {
				if (!b[amp[y].get(i)]) {
					q.add(amp[y].get(i));
					b[amp[y].get(i)] = true;
				}
			}
		}
	}
	public static void dfs(int x) {
		b[x] = true;
		for (int i = 0; i < amp[x].size(); i++) {
			if (!b[amp[x].get(i)]) {
				dfs(amp[x].get(i));
			}
		}
	}
	public int[] findMoves(int[] start){
		int n = start.length;
		int i = 0;
		ArrayList<Integer> amp = new ArrayList<>();
		while(i<n-1){
			if(start[i]==0){
				i++;continue;
			}
			int temp = start[i];
			start[i] = 0;
			int j = i+1;
			amp.add(i+1);
			while(temp>0){
				start[j%n]++;
				temp--;
				j++;
			}
			if(start[i]==0) i++;
		}
		int ans[] = new int[amp.size()];
		for(i = 0; i< amp.size();i++) ans[i] = amp.get(i);
		return ans;
	}
	static class Pair implements Comparable<Pair> {
		long u;
		long v;

		public Pair() {

		}

		public Pair(long u, long v) {
			this.u = u;
			this.v = v;
		}

		public int hashCode() {
			int hu = (int) (u ^ (u >>> 32));
			int hv = (int) (v ^ (v >>> 32));
			return 31 * hu + hv;
		}

		public boolean equals(Object o) {
			Pair other = (Pair) o;
			return (u == other.u && v == other.v);
		}

		public int compareTo(Pair other) {
			return Long.compare(u, other.u) != 0 ? (Long.compare(u, other.u))
					: (Long.compare(v, other.v));
		}

		public String toString() {
			return "[u=" + u + ", v=" + v + "]";
		}
	}

	public static int getParent(int x, int parent[]) {
		while (parent[x] != x) {
			parent[x] = parent[parent[x]];
			x = parent[x];
		}
		return x;
	}

	public static void seive(long n) {
		b = new boolean[(int) (n + 1)];
		Arrays.fill(b, true);
		b[0] = true;
		b[1] = false;
		for (int i = 2; i * i <= n; i++) {
			if (b[i]) {
				for (int p = 2 * i; p <= n; p += i) {
					b[p] = false;
					dist[i]+=cnt[p];
				}
			}
		}
	}

	public static void buildGraph(int n) {
		for (int i = 0; i < n; i++) {
			int x = sc.nextInt(), y = sc.nextInt();
			amp[--x].add(--y);
			amp[y].add(x);
		}
	}

	public static void multiBfs() {
		// System.out.println(hs);
		while (!q.isEmpty()) {
			int x = q.poll();
			for (int e : amp[x]) {
				if (!b[e]) {
					q.add(e);
					b[e] = true;
					sum[e] = x;
				} else {
					if (!hs.contains(x) && e != sum[x]) {
						System.out.println("NO");
						System.exit(0);
					}
				}
			}
		}
	}

	public static void getCycle(int x) {
		b[x] = true;
		for (int e : amp[x]) {
			if (b[e]) {
				p2 = x;
				if (e != sum[x]) {
					p1 = e;
					c1 = true;
					return;
				}
			} else {
				sum[e] = x;
				// System.out.print(e+" ");
				getCycle(e);
				if (c1)
					return;
			}
		}
		if (c1)
			return;
	}

	public static long count(long x, boolean b, long ans) {
		String str = Long.toString(x, 2);
		if (x == 1)
			return (ans + 1) % MOD;
		if (x == 0 && b)
			return (ans + 1) % MOD;
		else if (x == 0)
			return ans;
		if (str.length() > 1)
			ans = (long) ((ans + Math.pow(2, str.length() - 2) % MOD) % MOD);
		return count((long) (x - Math.pow(2, str.length() - 1)), !b, ans);
	}

	static boolean KMP(String pat, String txt) {
		int M = pat.length();
		int N = txt.length();

		// create lps[] that will hold the longest
		// prefix suffix values for pattern
		int lps[] = new int[M];
		int j = 0; // index for pat[]

		// Preprocess the pattern (calculate lps[]
		// array)
		computeLPSArray(pat, M, lps);

		int i = 0; // index for txt[]
		while (i < N) {
			if (pat.charAt(j) == txt.charAt(i)) {
				j++;
				i++;
			}
			if (j == M) {

				j = lps[j - 1];
				return true;
			}

			// mismatch after j matches
			else if (i < N && pat.charAt(j) != txt.charAt(i)) {
				// Do not match lps[0..lps[j-1]] characters,
				// they will match anyway
				if (j != 0)
					j = lps[j - 1];
				else
					i = i + 1;
			}
		}
		return false;
	}

	static void computeLPSArray(String pat, int M, int lps[]) {
		// length of the previous longest prefix suffix
		int len = 0;
		int i = 1;
		lps[0] = 0; // lps[0] is always 0

		// the loop calculates lps[i] for i = 1 to M-1
		while (i < M) {
			if (pat.charAt(i) == pat.charAt(len)) {
				len++;
				lps[i] = len;
				i++;
			} else // (pat[i] != pat[len])
			{
				// This is tricky. Consider the example.
				// AAACAAAA and i = 7. The idea is similar
				// to search step.
				if (len != 0) {
					len = lps[len - 1];

					// Also, note that we do not increment
					// i here
				} else // if (len == 0)
				{
					lps[i] = len;
					i++;
				}
			}
		}
	}

	static long power(long x, long y, long m) {
		if (y == 0)
			return 1;
		long p = power(x, y / 2, m) % m;
		p = (p * p) % m;

		return (y % 2 == 0) ? p : (x * p) % m;
	}

	private static void permutation(String prefix, String str) {
		int n = str.length();
		// if (n == 0) hs.add(prefix);
		// else {
		for (int i = 0; i < n; i++)
			permutation(prefix + str.charAt(i),
					str.substring(0, i) + str.substring(i + 1, n));
		// }
	}

	public static char give(char c1, char c2) {
		if (c1 != 'a' && c2 != 'a')
			return 'a';
		if (c1 != 'b' && c2 != 'b')
			return 'b';
		return 'c';
	}

	static class Graph {
		int vertex;
		long weight;
	}

	public static void buildTree(int n) {
		int arr[] = sc.nextIntArray(n);
		for (int i = 0; i < n; i++) {
			int x = arr[i] - 1;
			amp[i + 1].add(x);
			amp[x].add(i + 1);
		}
	}

	static class SegmentTree {
		long st[];
		long lazy[];

		SegmentTree(int n) {
			int size = 4 * n;
			st = new long[size];
			//lazy = new long[size];
			//build(0, n - 1, 1);
		}

		/*long[] build(int ss, int se, int si) {
			if (ss == se) {
				st[si][0] = 1;
				st[si][1] = 1;
				st[si][2] = 1;
				return st[si];
			}
			int mid = (ss + se) / 2;
			long a1[] = build(ss, mid, si * 2), a2[] = build(mid + 1, se,
					si * 2 + 1);
			long ans[] = new long[3];
			if (arr[mid] < arr[mid + 1]) {
				ans[1] = Math.max(a2[1], Math.max(a1[1], a1[2] + a2[0]));
				if (a1[1] == (mid - ss + 1))
					ans[0] = ans[1];
				else
					ans[0] = a1[0];
				if (a2[2] == (se - mid))
					ans[2] = ans[1];
				else
					ans[2] = a2[2];
			} else {
				ans[1] = Math.max(a1[1], a2[1]);
				ans[0] = a1[0];
				ans[2] = a2[2];
			}
			st[si] = ans;
			return st[si];
		}*/

		void update(int si, int ss, int se, int idx, int val) {
			if (ss == se) {
				arr1[idx] += val;
				st[si]+=val;
			}
			else {
				int mid = (ss + se) / 2;
				if(ss <= idx && idx <= mid)
		        {
		             update(2*si, ss, mid, idx, val);
		        }
		        else
		        { update(2*si+1, mid+1, se, idx, val);
		        }
				st[si] = st[2*si]+st[2*si+1];
			}
		}
		long get(int qs, int qe, int ss, int se, int si){
			if(qs>se || qe<ss) return 0;
			if (qs <= ss && qe >= se) {
				return st[si];
			}
			int mid = (ss+se)/2;
			return get(qs, qe, ss, mid, si * 2)+get(qs, qe, mid + 1, se, si * 2 + 1);
		}
		void updateRange(int node, int start, int end, int l, int r, int val)
		{
		    if(lazy[node] != 0)
		    {
		        // This node needs to be updated
		        st[node] += (end - start + 1) * lazy[node];    // Update it
		        if(start != end)
		        {
		            lazy[node*2] += lazy[node];                  // Mark child as lazy
		            lazy[node*2+1] += lazy[node];                // Mark child as lazy
		        }
		        lazy[node] = 0;                                  // Reset it
		    }
		    if(start > end || start > r || end < l)              // Current segment is not within range [l, r]
		        return;
		    if(start >= l && end <= r)
		    {
		        // Segment is fully within range
		        st[node] += (end - start + 1) * val;
		        if(start != end)
		        {
		            // Not leaf node
		            lazy[node*2] += val;
		            lazy[node*2+1] += val;
		        }
		        return;
		    }
		    int mid = (start + end) / 2;
		    updateRange(node*2, start, mid, l, r, val);        // Updating left child
		    updateRange(node*2 + 1, mid + 1, end, l, r, val);   // Updating right child
		    st[node] = st[node*2] + st[node*2+1];        // Updating root with max value
		}

		int queryRange(int node, int start, int end, int l, int r)
		{
		    if(start > end || start > r || end < l)
		        return 0;         // Out of range
		    if(lazy[node] != 0)
		    {
		        // This node needs to be updated
		        st[node] += (end - start + 1) * lazy[node];            // Update it
		        if(start != end)
		        {
		            lazy[node*2] += lazy[node];         // Mark child as lazy
		            lazy[node*2+1] += lazy[node];    // Mark child as lazy
		        }
		        lazy[node] = 0;                 // Reset it
		    }
		    if(start >= l && end <= r)             // Current segment is totally within range [l, r]
		        return (int) st[node];
		    int mid = (start + end) / 2;
		    int p1 = queryRange(node*2, start, mid, l, r);         // Query left child
		    int p2 = queryRange(node*2 + 1, mid + 1, end, l, r); // Query right child
		    return (p1 + p2);
		}
		void print() {
			for (int i = 0; i < st.length; i++) {
				System.out.print(st[i]+" ");
			}
			System.out.println();
		}
	}

	static int convert(int x) {
		int cnt = 0;
		String str = Integer.toBinaryString(x);
		// System.out.println(str);
		for (int i = 0; i < str.length(); i++) {
			if (str.charAt(i) == '1') {
				cnt++;
			}
		}
		int ans = (int) Math.pow(3, 6 - cnt);
		return ans;
	}

	static class Node2 {
		Node2 left = null;
		Node2 right = null;
		Node2 parent = null;
		int data;
	}

	static class BinarySearchTree {
		Node2 root = null;
		int height = 0;
		int max = 0;
		int cnt = 1;
		ArrayList<Integer> parent = new ArrayList<>();
		HashMap<Integer, Integer> hm = new HashMap<>();

		public void insert(int x) {
			Node2 n = new Node2();
			n.data = x;
			if (root == null) {
				root = n;
			} else {
				Node2 temp = root, temp2 = null;
				while (temp != null) {
					temp2 = temp;
					if (x > temp.data)
						temp = temp.right;
					else
						temp = temp.left;
				}
				if (x > temp2.data)
					temp2.right = n;
				else
					temp2.left = n;
				n.parent = temp2;
				parent.add(temp2.data);
			}
		}

		public Node2 getSomething(int x, int y, Node2 n) {
			if (n.data == x || n.data == y)
				return n;
			else if (n.data > x && n.data < y)
				return n;
			else if (n.data < x && n.data < y)
				return getSomething(x, y, n.right);
			else
				return getSomething(x, y, n.left);
		}

		public Node2 search(int x, Node2 n) {
			if (x == n.data) {
				max = Math.max(max, n.data);
				return n;
			}
			if (x > n.data) {
				max = Math.max(max, n.data);
				return search(x, n.right);
			} else {
				max = Math.max(max, n.data);
				return search(x, n.left);
			}
		}

		public int getHeight(Node2 n) {
			if (n == null)
				return 0;
			height = 1 + Math.max(getHeight(n.left), getHeight(n.right));
			return height;
		}
	}

	static long findDiff(long[] arr, long[] brr, int m) {
		int i = 0, j = 0;
		long fa = 1000000000000L;
		while (i < m && j < m) {
			long x = arr[i] - brr[j];
			if (x >= 0) {
				if (x < fa)
					fa = x;
				j++;
			} else {
				if ((-x) < fa)
					fa = -x;
				i++;
			}
		}
		return fa;
	}

	public static long max(long x, long y, long z) {
		if (x >= y && x >= z)
			return x;
		if (y >= x && y >= z)
			return y;
		return z;
	}

	static long modInverse(long a, long mOD2) {
		return power(a, mOD2 - 2, mOD2);
	}

	static long power2(long x, BigInteger y, long m) {
		long ans = 1;
		BigInteger two = new BigInteger("2");
		while (y.compareTo(BigInteger.ZERO) > 0) {
			if (y.getLowestSetBit() == y.bitCount()) {
				x = (x * x) % MOD;
				y = y.divide(two);
			} else {
				ans = (ans * x) % MOD;
				y = y.subtract(BigInteger.ONE);
			}
		}
		return ans;
	}

	static BigInteger power2(BigInteger x, BigInteger y, BigInteger m) {
		BigInteger ans = new BigInteger("1");
		BigInteger one = new BigInteger("1");
		BigInteger two = new BigInteger("2");
		BigInteger zero = new BigInteger("0");
		while (y.compareTo(zero) > 0) {
			// System.out.println(y);
			if (y.mod(two).equals(one)) {
				ans = ans.multiply(x).mod(m);
				y = y.subtract(one);
			} else {
				x = x.multiply(x).mod(m);
				y = y.divide(two);
			}
		}
		return ans;
	}

	static BigInteger power(BigInteger x, BigInteger y, BigInteger m) {
		if (y.equals(0))
			return (new BigInteger("1"));
		BigInteger p = power(x, y.divide(new BigInteger("2")), m).mod(m);
		p = (p.multiply(p)).mod(m);

		return (y.mod(new BigInteger("2")).equals(0)) ? p : (p.multiply(x))
				.mod(m);
	}

	static long d, x, y;

	public static void extendedEuclidian(long a, long b) {
		if (b == 0) {
			d = a;
			x = 1;
			y = 0;
		} else {
			extendedEuclidian(b, a % b);
			int temp = (int) x;
			x = y;
			y = temp - (a / b) * y;
		}
	}

	public static long gcd(long n, long m) {
		if (m != 0)
			return gcd(m, n % m);
		else
			return n;
	}

	public static class FasterScanner {
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = System.in.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			return nextIntArray(n, 0);
		}

		public int[] nextIntArray(int n, int off) {
			int[] arr = new int[n + off];
			for (int i = 0; i < n; i++) {
				arr[i + off] = nextInt();
			}
			return arr;
		}

		public long[] nextLongArray(int n) {
			return nextLongArray(n, 0);
		}

		public long[] nextLongArray(int n, int off) {
			long[] arr = new long[n + off];
			for (int i = 0; i < n; i++) {
				arr[i + off] = nextLong();
			}
			return arr;
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB
    {
        static int V;
        static int E;
        static ArrayList<Integer> G;
        static boolean visited;
        static long nodes;
        static long edges;

        static void dfs(int u)
        {
            if (visited[u]) return;

            visited[u] = true;
            nodes++;
            for (int i = 0; i < G[u].size(); i++)
            {
                edges++;
                dfs(G[u].get(i));
            }
        }

        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            V = in.nextInt();
            E = in.nextInt();
            G = new ArrayList[V];
            for (int i = 0; i < V; i++) G[i] = new ArrayList<>(1);

            for (int i = 0; i < E; i++)
            {
                int u = in.nextInt() - 1;
                int v = in.nextInt() - 1;
                G[u].add(v);
                G[v].add(u);
            }
            visited = new boolean[V];
            boolean ok = true;
            for (int i = 0; i < V; i++)
            {
                if (!visited[i])
                {
                    nodes = edges = 0;
                    dfs(i);
                    if (nodes * (nodes - 1) != edges)
                    {
                        ok = false;
                        break;
                    }
                }
            }
            out.println(ok ? "YES" : "NO");
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        static int V;
        static int E;
        static ArrayList<Integer> G[];
        static boolean visited[];
        static long nodes;
        static long edges;

        static void dfs(int u)
        {
            if (visited[u]) return;
            visited[u] = true;
            nodes++;
            for (int i = 0; i < G[u].size(); i++)
            {
                edges++;
                dfs(G[u].get(i));
            }
        }

        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            V = in.nextInt();
            E = in.nextInt();
            G = new ArrayList[V];
            for (int i = 0; i < V; i++) G[i] = new ArrayList<>();

            for (int i = 0; i < E; i++)
            {
                int u = in.nextInt() - 1;
                int v = in.nextInt() - 1;
                G[u].add(v);
                G[v].add(u);
            }
            visited = new boolean[V];
            boolean ok = true;
            for (int i = 0; i < V; i++)
            {
                if (!visited[i])
                {
                    nodes = edges = 0;
                    dfs(i);
                    if (nodes * (nodes - 1) != edges)
                    {
                        ok = false;
                        break;
                    }
                }
            }
            out.println(ok ? "YES" : "NO");
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Objects;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB
    {
        static Set<Edge> edges = new HashSet<>();
        static int seen;
        static int seenEdges;

        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            seen = 0;
            seenEdges = 0;
            int N = in.nextInt();
            int M = in.nextInt();
            List<Integer>[] G = new List[N + 1];
            fill(G, M, in);
            boolean set[] = new boolean[N + 1];

            int previous = seen;
            for (int i = 1; i <= N; i++)
            {
                if (G[i] == null || set[i]) continue;
                edges = new HashSet<>();
                visit(G, set, i);
                int current = seen;
                int size = current - previous;
                previous = current;
                if ((long) edges.size() != ((long) size * (size - 1)) / 2L)
                {
                    out.println("NO");
                    return;
                }
            }
            out.println("YES");
        }

        private void visit(List<Integer>[] G, boolean[] set, int current)
        {
            if (set[current]) return;

            set[current] = true;
            seen++;
            if (G[current] == null) return;

            for (int n : G[current])
            {
                edges.add(new Edge(current, n));
                visit(G, set, n);
            }
        }

        private void fill(List<Integer>[] G, int m, Scanner in)
        {
            while (m-- > 0)
            {
                int from = in.nextInt(), to = in.nextInt();
                if (G[from] == null)
                {
                    G[from] = new ArrayList<>();
                }
                G[from].add(to);
                if (G[to] == null)
                {
                    G[to] = new ArrayList<>();
                }
                G[to].add(from);
            }
        }

    }

    static class Edge
    {
        int from;
        int to;

        Edge(int from, int to)
        {
            this.from = Math.min(from, to);
            this.to = Math.max(from, to);
            ;
        }

        public boolean equals(Object o)
        {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Edge edge = (Edge) o;
            return from == edge.from &&
                           to == edge.to;
        }

        public int hashCode()
        {
            return Objects.hash(from, to);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Objects;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB
    {
        static Set<Edge> edges = new HashSet<>();

        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int N = in.nextInt();
            int M = in.nextInt();
            List<Integer>[] G = new List[N + 1];
            fill(G, M, in);
            Set<Integer> set = new HashSet<>();

            int previous = set.size();
            for (int i = 1; i <= N; i++)
            {
                if (G[i] == null || set.contains(i)) continue;
                edges = new HashSet<>();
                visit(G, set, i);
                int current = set.size();
                int size = current - previous;
                previous = current;
                if (edges.size() != (size * (size - 1)) / 2)
                {
                    out.println("NO");
                    return;
                }
            }
            out.println("YES");
        }

        private void visit(List<Integer>[] G, Set<Integer> set, int current)
        {
            if (set.contains(current)) return;

            set.add(current);
            if (G[current] == null) return;

            for (int n : G[current])
            {
                edges.add(new Edge(current, n));
                visit(G, set, n);
            }
        }

        private void fill(List<Integer>[] G, int m, Scanner in)
        {
            while (m-- > 0)
            {
                int from = in.nextInt(), to = in.nextInt();
                if (G[from] == null)
                {
                    G[from] = new ArrayList<>();
                }
                G[from].add(to);
            }
        }

    }

    static class Edge
    {
        int from;
        int to;

        Edge(int from, int to)
        {
            this.from = from;
            this.to = to;
        }

        public boolean equals(Object o)
        {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Edge edge = (Edge) o;
            return from == edge.from &&
                           to == edge.to;
        }

        public int hashCode()
        {
            return Objects.hash(from, to);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Objects;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB
    {
        static Set<Edge> edges = new HashSet<>();

        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int N = in.nextInt();
            int M = in.nextInt();
            List<Integer>[] G = new List[N + 1];
            fill(G, M, in);
            Set<Integer> set = new HashSet<>();

            int previous = set.size();
            for (int i = 1; i <= N; i++)
            {
                if (G[i] == null || set.contains(i)) continue;
                edges = new HashSet<>();
                visit(G, set, i);
                int current = set.size();
                int size = current - previous;
                previous = current;
                if (edges.size() != (size * (size - 1)) / 2)
                {
                    out.println("NO");
                    return;
                }
            }
            out.println("YES");
        }

        private void visit(List<Integer>[] G, Set<Integer> set, int current)
        {
            if (set.contains(current)) return;

            set.add(current);
            if (G[current] == null) return;

            for (int n : G[current])
            {
                edges.add(new Edge(current, n));
                visit(G, set, n);
            }
        }

        private void fill(List<Integer>[] G, int m, Scanner in)
        {
            while (m-- > 0)
            {
                int from = in.nextInt(), to = in.nextInt();
                if (G[from] == null)
                {
                    G[from] = new ArrayList<>();
                }
                G[from].add(to);
                if (G[to] == null)
                {
                    G[to] = new ArrayList<>();
                }
                G[to].add(from);
            }
        }

    }

    static class Edge
    {
        int from;
        int to;

        Edge(int from, int to)
        {
            this.from = Math.min(from, to);
            this.to = Math.max(from, to);
            ;
        }

        public boolean equals(Object o)
        {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Edge edge = (Edge) o;
            return from == edge.from &&
                           to == edge.to;
        }

        public int hashCode()
        {
            return Objects.hash(from, to);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Objects;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB
    {
        static Set<Edge> edges = new HashSet<>();
        static int seen;
        static int seenEdges;

        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            seen = 0;
            seenEdges = 0;
            int N = in.nextInt();
            int M = in.nextInt();
            List<Integer>[] G = new List[N + 1];
            fill(G, M, in);
            boolean set[] = new boolean[N + 1];

            int previous = seen;
            for (int i = 1; i <= N; i++)
            {
                if (G[i] == null || set[i]) continue;
                edges = new HashSet<>();
                visit(G, set, i);
                int current = seen;
                int size = current - previous;
                previous = current;
                if (edges.size() != (size * (size - 1)) / 2)
                {
                    out.println("NO");
                    return;
                }
            }
            out.println("YES");
        }

        private void visit(List<Integer>[] G, boolean[] set, int current)
        {
            if (set[current]) return;

            set[current] = true;
            seen++;
            if (G[current] == null) return;

            for (int n : G[current])
            {
                edges.add(new Edge(current, n));
                visit(G, set, n);
            }
        }

        private void fill(List<Integer>[] G, int m, Scanner in)
        {
            while (m-- > 0)
            {
                int from = in.nextInt(), to = in.nextInt();
                if (G[from] == null)
                {
                    G[from] = new ArrayList<>();
                }
                G[from].add(to);
                if (G[to] == null)
                {
                    G[to] = new ArrayList<>();
                }
                G[to].add(from);
            }
        }

    }

    static class Edge
    {
        int from;
        int to;

        Edge(int from, int to)
        {
            this.from = Math.min(from, to);
            this.to = Math.max(from, to);
            ;
        }

        public boolean equals(Object o)
        {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Edge edge = (Edge) o;
            return from == edge.from &&
                           to == edge.to;
        }

        public int hashCode()
        {
            return Objects.hash(from, to);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB
    {
        static boolean[][] edges;
        static int seen;
        static long seenEdges;

        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            seen = 0;
            int N = in.nextInt();
            int M = in.nextInt();
            List<Integer>[] G = new List[N + 1];
            fill(G, M, in);
            boolean set[] = new boolean[N + 1];

            int previous = seen;
            for (int i = 1; i <= N; i++)
            {
                if (G[i] == null || set[i]) continue;
                edges = new boolean[N + 1][];
                seenEdges = 0;
                visit(G, set, i);
                int current = seen;
                int size = current - previous;
                previous = current;
                if (seenEdges != ((long) size * (size - 1)) / 2L)
                {
                    out.println("NO");
                    return;
                }
            }
            out.println("YES");
        }

        private void visit(List<Integer>[] G, boolean[] set, int current)
        {
            if (set[current]) return;

            set[current] = true;
            seen++;
            if (G[current] == null) return;

            for (int n : G[current])
            {
                if (edges[Math.min(current, n)] == null || !edges[Math.min(current, n)][Math.max(current, n)])
                {
                    if (edges[Math.min(current, n)] == null)
                        edges[Math.min(current, n)] = new boolean[edges.length + 1];
                    seenEdges++;
                    edges[Math.min(current, n)][Math.max(current, n)] = true;
                }
                visit(G, set, n);
            }
        }

        private void fill(List<Integer>[] G, int m, Scanner in)
        {
            while (m-- > 0)
            {
                int from = in.nextInt(), to = in.nextInt();
                if (G[from] == null)
                {
                    G[from] = new ArrayList<>();
                }
                G[from].add(to);
                if (G[to] == null)
                {
                    G[to] = new ArrayList<>();
                }
                G[to].add(from);
            }
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB
    {
        static Set[] edges;
        static int seen;
        static long edgesSeen;

        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            seen = 0;
            int N = in.nextInt();
            int M = in.nextInt();
            List<Integer>[] G = new List[N + 1];
            fill(G, M, in);
            boolean set[] = new boolean[N + 1];

            int previous = seen;
            for (int i = 1; i <= N; i++)
            {
                if (G[i] == null || set[i]) continue;
                edges = new HashSet[N + 1];
                edgesSeen = 0;
                visit(G, set, i);
                int current = seen;
                int size = current - previous;
                previous = current;
                if (edgesSeen != ((long) size * (size - 1)) / 2L)
                {
                    out.println("NO");
                    return;
                }
            }
            out.println("YES");
        }

        private void visit(List<Integer>[] G, boolean[] set, int current)
        {
            if (set[current]) return;

            set[current] = true;
            seen++;
            if (G[current] == null) return;

            for (int n : G[current])
            {
                if (edges[Math.min(n, current)] == null || !edges[Math.min(n, current)].contains(Math.max(n, current)))
                {
                    if (edges[Math.min(n, current)] == null) edges[Math.min(n, current)] = new HashSet();
                    edges[Math.min(n, current)].add(Math.max(n, current));
                    edgesSeen++;
                }
                visit(G, set, n);
            }
        }

        private void fill(List<Integer>[] G, int m, Scanner in)
        {
            while (m-- > 0)
            {
                int from = in.nextInt(), to = in.nextInt();
                if (G[from] == null)
                {
                    G[from] = new ArrayList<>();
                }
                G[from].add(to);
                if (G[to] == null)
                {
                    G[to] = new ArrayList<>();
                }
                G[to].add(from);
            }
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB
    {
        static boolean[][] edges;
        static int seen;
        static long seenEdges;

        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            seen = 0;
            int N = in.nextInt();
            int M = in.nextInt();
            List<Integer>[] G = new List[N + 1];
            fill(G, M, in);
            boolean set[] = new boolean[N + 1];

            int previous = seen;
            for (int i = 1; i <= N; i++)
            {
                if (G[i] == null || set[i]) continue;
                edges = new boolean[N + 1][N + 1];
                seenEdges = 0;
                visit(G, set, i);
                int current = seen;
                int size = current - previous;
                previous = current;
                if (seenEdges != ((long) size * (size - 1)) / 2L)
                {
                    out.println("NO");
                    return;
                }
            }
            out.println("YES");
        }

        private void visit(List<Integer>[] G, boolean[] set, int current)
        {
            if (set[current]) return;

            set[current] = true;
            seen++;
            if (G[current] == null) return;

            for (int n : G[current])
            {
                if (!edges[Math.min(current, n)][Math.max(current, n)])
                {
                    seenEdges++;
                    edges[Math.min(current, n)][Math.max(current, n)] = true;
                }
                visit(G, set, n);
            }
        }

        private void fill(List<Integer>[] G, int m, Scanner in)
        {
            while (m-- > 0)
            {
                int from = in.nextInt(), to = in.nextInt();
                if (G[from] == null)
                {
                    G[from] = new ArrayList<>();
                }
                G[from].add(to);
                if (G[to] == null)
                {
                    G[to] = new ArrayList<>();
                }
                G[to].add(from);
            }
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB
    {
        static int V;
        static int E;
        static ArrayList<Integer> G;
        static boolean visited;
        static long nodes;
        static long edges;

        static void dfs(int u)
        {
            if (visited[u]) return;
            visited[u] = true;
            nodes++;
            for (int i = 0; i < G[u].size(); i++)
            {
                edges++;
                dfs(G[u].get(i));
            }
        }

        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            V = in.nextInt();
            E = in.nextInt();
            G = new ArrayList[V];
            for (int i = 0; i < V; i++) G[i] = new ArrayList<>();

            for (int i = 0; i < E; i++)
            {
                int u = in.nextInt() - 1;
                int v = in.nextInt() - 1;
                G[u].add(v);
                G[v].add(u);
            }
            visited = new boolean[V];
            boolean ok = true;
            for (int i = 0; i < V; i++)
            {
                if (!visited[i])
                {
                    nodes = edges = 0;
                    dfs(i);
                    if (nodes * (nodes - 1) != edges)
                    {
                        ok = false;
                        break;
                    }
                }
            }
            out.println(ok ? "YES" : "NO");
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB
    {
        static int V;
        static int E;
        static ArrayList<Integer> G;
        static boolean visited;
        static long nodes;
        static long edges;

        static void dfs(int u)
        {
            if (visited[u]) return;
            visited[u] = true;
            nodes++;
            for (int i = 0; i < G[u].size(); i++)
            {
                edges++;
                dfs(G[u].get(i));
            }
        }

        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            V = in.nextInt();
            E = in.nextInt();
            G = new ArrayList[V];
            for (int i = 0; i < V; i++) G[i] = new ArrayList<>(1);

            for (int i = 0; i < E; i++)
            {
                int u = in.nextInt() - 1;
                int v = in.nextInt() - 1;
                G[u].add(v);
                G[v].add(u);
            }
            visited = new boolean[V];
            boolean ok = true;
            for (int i = 0; i < V; i++)
            {
                if (!visited[i])
                {
                    nodes = edges = 0;
                    dfs(i);
                    if (nodes * (nodes - 1) != edges)
                    {
                        ok = false;
                        break;
                    }
                }
            }
            out.println(ok ? "YES" : "NO");
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.List;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.LinkedHashSet;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        inclass in = new inclass(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BBearAndFriendshipCondition solver = new BBearAndFriendshipCondition();
        solver.solve(1, in, out);
        out.close();
    }

    static class BBearAndFriendshipCondition {
        private List<Integer>[] g;

        public void solve(int testNumber, inclass in, PrintWriter out) {
            int n = in.nextInt(), m = in.nextInt();
            g = new ArrayList[n];
            for (int i = 0; i < n; i++) {
                g[i] = new ArrayList<>();
            }
            for (int i = 0; i < m; i++) {
                int a = in.nextInt() - 1;
                int b = in.nextInt() - 1;
                g[a].add(b);
                g[b].add(a);
            }
            boolean[] vis = new boolean[n];
            HashSet<Integer> set;
            for (int i = 0; i < n; i++) {
                if (!vis[i]) {
                    set = new LinkedHashSet<>();
                    dfs(i, vis, set);
                    long x = set.size();
                    long should_be = (x * (x - 1)) / 2L;
                    long degree = 0L;
                    for (int u : set) {
                        degree += (long) g[u].size();
                    }
                    if (should_be != degree / 2) {
                        out.println("NO");
                        return;
                    }
                }

            }
            out.println("YES");
        }

        private void dfs(int u, boolean[] vis, HashSet<Integer> set) {
            vis[u] = true;
            set.add(u);
            for (int v : g[u]) {
                if (!vis[v]) {
                    dfs(v, vis, set);
                }
            }
        }

    }

    static class inclass {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private inclass.SpaceCharFilter filter;

        public inclass(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.List;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.LinkedHashSet;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        inclass in = new inclass(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BBearAndFriendshipCondition solver = new BBearAndFriendshipCondition();
        solver.solve(1, in, out);
        out.close();
    }

    static class BBearAndFriendshipCondition {
        private List<Integer>[] g;

        public void solve(int testNumber, inclass in, PrintWriter out) {
            int n = in.nextInt(), m = in.nextInt();
            g = new ArrayList[n];
            for (int i = 0; i < n; i++) {
                g[i] = new ArrayList<>();
            }
            for (int i = 0; i < m; i++) {
                int a = in.nextInt() - 1;
                int b = in.nextInt() - 1;
                g[a].add(b);
                g[b].add(a);
            }
            boolean[] vis = new boolean[n];
            HashSet<Integer> set;
            int ans = 0;
            for (int i = 0; i < n; i++) {
                if (!vis[i]) {
                    set = new LinkedHashSet<>();
                    dfs(i, vis, set);
                    int x = set.size();
                    int should_be = (x * (x - 1)) / 2;
                    int degree = 0;
                    for (int u : set) {
                        degree += g[u].size();
                    }
                    if (should_be != degree / 2) {
                        out.println("NO");
                        return;
                    }
                }

            }
            out.println("YES");
        }

        private void dfs(int u, boolean[] vis, HashSet<Integer> set) {
            vis[u] = true;
            set.add(u);
            for (int v : g[u]) {
                if (!vis[v]) {
                    dfs(v, vis, set);
                }
            }
        }

    }

    static class inclass {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private inclass.SpaceCharFilter filter;

        public inclass(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), m = in.nextInt();
		ArrayList<Integer>[] g = new ArrayList[n];
		visited = new boolean[n];
		for(int i=0;i<n;i++) g[i] = new ArrayList<>();
		for(int i=0;i<m;i++){
			int u = in.nextInt()-1, v = in.nextInt()-1;
			g[u].add(v);
			g[v].add(u);
		}
		ArrayList<ArrayList<Integer>> list = new ArrayList<>();
		for(int i=0;i<n;i++){
			if(!visited[i]){
				ArrayList<Integer> cc = new ArrayList<>();
				dfs(g, i, cc);
				list.add(cc);
			}
		}
		for(int i=0;i<list.size();i++){
			int count = 0;
			int e = list.get(i).size();
			for(int j=0;j<list.get(i).size();j++){
				count += g[list.get(i).get(j)].size();
			}
			if(count != (e*(e-1))){
				System.out.println("NO");
				return;
			}
		}
		System.out.println("YES");
	}
	static boolean[] visited;
	public static void dfs(ArrayList<Integer>[] g, int node, ArrayList<Integer> cc){
		visited[node] = true;
		cc.add(node);
		for(int i:g[node]){
			if(!visited[i]) dfs(g, i, cc);
		}
	}

}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), m = in.nextInt();
		ArrayList<Integer>[] g = new ArrayList[n];
		visited = new boolean[n];
		for(int i=0;i<n;i++) g[i] = new ArrayList<>();
		for(int i=0;i<m;i++){
			int u = in.nextInt()-1, v = in.nextInt()-1;
			g[u].add(v);
			g[v].add(u);
		}
		ArrayList<ArrayList<Integer>> list = new ArrayList<>();
		for(int i=0;i<n;i++){
			if(!visited[i]){
				ArrayList<Integer> cc = new ArrayList<>();
				dfs(g, i, cc);
				list.add(cc);
			}
		}
		boolean work = true;
		for(int i=0;i<list.size();i++){
			int count = 0;
			int e = list.get(i).size();
			for(int j=0;j<list.get(i).size();j++){
				count += g[list.get(i).get(j)].size();
			}
			work = count == (e*(e-1));
		}
		System.out.println(work ? "YES" : "NO");
	}
	static boolean[] visited;
	public static void dfs(ArrayList<Integer>[] g, int node, ArrayList<Integer> cc){
		visited[node] = true;
		cc.add(node);
		for(int i:g[node]){
			if(!visited[i]) dfs(g, i, cc);
		}
	}

}


import java.io.*;
import java.util.*;

public class Main {
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
	public static void main(String[] args) {
		FastReader in = new FastReader();
		int n = in.nextInt(), m = in.nextInt();
		ArrayList<Integer>[] g = new ArrayList[n];
		visited = new boolean[n];
		for(int i=0;i<n;i++) g[i] = new ArrayList<>();
		for(int i=0;i<m;i++){
			int u = in.nextInt()-1, v = in.nextInt()-1;
			g[u].add(v);
			g[v].add(u);
		}
		for(int i=0;i<n;i++){
			if(!visited[i]){
				long[] d = {0,0};
				dfs(g, i, d);
				if(d[0]*(d[0]-1) != d[1]){
					System.out.println("NO");
					return;
				}
			}
		}
		System.out.println("YES");
	}
	static boolean[] visited;
	public static void dfs(ArrayList<Integer>[] g, int node, long[] d){
		visited[node] = true;
		d[0]++;
		d[1] += g[node].size();
		for(int i:g[node]){
			if(!visited[i]) dfs(g, i, d);
		}
	}

}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), m = in.nextInt();
		ArrayList<Integer>[] g = new ArrayList[n];
		visited = new boolean[n];
		for(int i=0;i<n;i++) g[i] = new ArrayList<>();
		for(int i=0;i<m;i++){
			int u = in.nextInt()-1, v = in.nextInt()-1;
			g[u].add(v);
			g[v].add(u);
		}
		for(int i=0;i<n;i++){
			if(!visited[i]){
				int[] d = {0,0};
				dfs(g, i, d);
				if(d[0]*(d[0]-1) != d[1]){
					System.out.println("NO");
					return;
				}
			}
		}
		System.out.println("YES");
	}
	static boolean[] visited;
	public static void dfs(ArrayList<Integer>[] g, int node, int[] d){
		visited[node] = true;
		d[0]++;
		d[1] += g[node].size();
		for(int i:g[node]){
			if(!visited[i]) dfs(g, i, d);
		}
	}

}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), m = in.nextInt();
		ArrayList<Integer>[] g = new ArrayList[n];
		visited = new boolean[n];
		for(int i=0;i<n;i++) g[i] = new ArrayList<>();
		for(int i=0;i<m;i++){
			int u = in.nextInt()-1, v = in.nextInt()-1;
			g[u].add(v);
			g[v].add(u);
		}
		ArrayList<ArrayList<Integer>> list = new ArrayList<>();
		for(int i=0;i<n;i++){
			if(!visited[i]){
				ArrayList<Integer> cc = new ArrayList<>();
				dfs(g, i, cc);
				list.add(cc);
			}
		}
		for(int i=0;i<list.size();i++){
			int count = 0;
			int e = list.get(i).size();
			for(int j=0;j<list.get(i).size();j++){
				count += g[list.get(i).get(j)].size();
			}
			if(count == (e*(e-1)))
				System.out.println("NO");
		}
		System.out.println("YES");
	}
	static boolean[] visited;
	public static void dfs(ArrayList<Integer>[] g, int node, ArrayList<Integer> cc){
		visited[node] = true;
		cc.add(node);
		for(int i:g[node]){
			if(!visited[i]) dfs(g, i, cc);
		}
	}

}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), m = in.nextInt();
		ArrayList<Integer>[] g = new ArrayList[n];
		visited = new boolean[n];
		for(int i=0;i<n;i++) g[i] = new ArrayList<>();
		for(int i=0;i<m;i++){
			int u = in.nextInt()-1, v = in.nextInt()-1;
			g[u].add(v);
			g[v].add(u);
		}
		for(int i=0;i<n;i++){
			if(!visited[i]){
				long[] d = {0,0};
				dfs(g, i, d);
				if(d[0]*(d[0]-1) != d[1]){
					System.out.println("NO");
					return;
				}
			}
		}
		System.out.println("YES");
	}
	static boolean[] visited;
	public static void dfs(ArrayList<Integer>[] g, int node, long[] d){
		visited[node] = true;
		d[0]++;
		d[1] += g[node].size();
		for(int i:g[node]){
			if(!visited[i]) dfs(g, i, d);
		}
	}

}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), m = in.nextInt();
		ArrayList<Integer>[] g = new ArrayList[n];
		visited = new boolean[n];
		for(int i=0;i<n;i++) g[i] = new ArrayList<>();
		for(int i=0;i<m;i++){
			int u = in.nextInt()-1, v = in.nextInt()-1;
			g[u].add(v);
			g[v].add(u);
		}
		ArrayList<ArrayList<Integer>> list = new ArrayList<>();
		for(int i=0;i<n;i++){
			if(!visited[i]){
				ArrayList<Integer> cc = new ArrayList<>();
				dfs(g, i, cc);
				list.add(cc);
			}
		}
		for(int i=0;i<list.size();i++){
			int count = 0;
			int e = list.get(i).size();
			for(int j=0;j<list.get(i).size();j++){
				count += g[list.get(i).get(j)].size();
			}
			if(count != (e*(e-1)))
				System.out.println("NO");
		}
		System.out.println("YES");
	}
	static boolean[] visited;
	public static void dfs(ArrayList<Integer>[] g, int node, ArrayList<Integer> cc){
		visited[node] = true;
		cc.add(node);
		for(int i:g[node]){
			if(!visited[i]) dfs(g, i, cc);
		}
	}

}


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Map;
import java.io.*;
import java.util.InputMismatchException;
public class SwapWords {
static class pair{
 int f,s;
 pair(int x,int y){
  f=x;s=y;
 }
}

    public static void main(String[] args)throws Exception {
      FasterScanner in = new FasterScanner();
      int n =in.nextInt();int m =in.nextInt();
      ArrayList<ArrayList<Integer>> arr = new ArrayList<ArrayList<Integer>>();
      HashMap<String,Boolean> map1 = new HashMap<String,Boolean>();
      HashMap<String,Boolean> map2 = new HashMap<String,Boolean>();
      pair []  p= new pair[m];
     for(int i= 0;i<n+1;i++)
          arr.add(new ArrayList<Integer>());

        long a=System.currentTimeMillis();

   for(int i=0;i<m;i++){
       int c=in.nextInt();int d=in.nextInt();
       p[i]=new pair(c,d);
       arr.get(c).add(d);

       map1.put(c+" "+d, true);
       map1.put(d+" "+c, true);

   }

   for(int i= 0;i<m;i++){

       for(int j=0;j<arr.get(p[i].s).size();j++){

           map2.put(p[i].f+" "+arr.get(p[i].s).get(j),true);
           map2.put(arr.get(p[i].s).get(j)+" "+p[i].f,true);
       }
       }
   boolean t=true;
    for (Map.Entry<String, Boolean> entry : map2.entrySet())
{ if(map1.get(entry.getKey())==null){
            t=false;break;
}

}

   if(t)
         System.out.println("YES");
   else
         System.out.println("NO");

    }
   static   class FasterScanner {
	private InputStream mIs;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;

	public FasterScanner() {
		this(System.in);
	}

	public FasterScanner(InputStream is) {
		mIs = is;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = mIs.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public String nextLine() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

	public String nextString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long nextLong() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public int nextInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public boolean isEndOfLine(int c) {
		return c == '\n' || c == '\r' || c == -1;
	}

}}


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Map;
public class SwapWords {
static class pair{
 int f,s;
 pair(int x,int y){
  f=x;s=y;
 }
}

    public static void main(String[] args)throws Exception {
      reader in = new reader(System.in);
      int n =in.nextInt();int m =in.nextInt();
      ArrayList<ArrayList<Integer>> arr = new ArrayList<ArrayList<Integer>>();
      HashMap<String,Boolean> map1 = new HashMap<String,Boolean>();
      HashMap<String,Boolean> map2 = new HashMap<String,Boolean>();
      pair []  p= new pair[m];
      for(int i= 0;i<n+1;i++)
          arr.add(new ArrayList<Integer>());
   for(int i=0;i<m;i++){
       int c=in.nextInt();int d=in.nextInt();
       p[i]=new pair(c,d);
       arr.get(c).add(d);
       String x=c+"";String y=d+"";
       map1.put(x+" "+y, true);
       map1.put(y+" "+x,true);
   }
   for(int i= 0;i<m;i++){
       for(int j=0;j<arr.get(p[i].s).size();j++){
           map2.put(p[i].f+" "+arr.get(p[i].s).get(j),true);
           map2.put(arr.get(p[i].s).get(j)+" "+p[i].f,true);
       }
       }
   boolean t=true;
    for (Map.Entry<String, Boolean> entry : map2.entrySet())
{ if(map1.get(entry.getKey())==null){
            t=false;break;
}

}

   if(t)
         System.out.println("YES");
   else
         System.out.println("NO");

    }
     static class reader{
      BufferedReader read ;
      StringTokenizer tok;
      public reader(InputStream stream){
          read= new BufferedReader(new InputStreamReader(stream));
          tok=null;

      }
       String next()throws Exception{

          while(tok==null||!tok.hasMoreElements()){
              tok= new StringTokenizer(read.readLine());

          }
          return tok.nextToken();
      }

       int nextInt()throws Exception{
           return Integer.parseInt(next());

       }
    }
}


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
import java.util.HashMap;
public class JavaApplication1{
      static  class pair{
     int f, s;
     pair(int x,int y){
      f=x;s=y;
     }
    }

 public static void main(String [] args)throws Exception{
  reader in = new reader(System.in);
   int  a=in.nextInt();int  b=in.nextInt();
   int arr[]= new int[a+1];
   HashMap<String,Boolean> map1 = new HashMap<String,Boolean>();
   HashMap<String,Boolean> map2 = new HashMap<String,Boolean>();
   pair []  p= new pair[b];
   for(int i=0;i<b;i++){
       int c=in.nextInt();int d=in.nextInt();
       p[i]=new pair(c,d);
       String x=c+"";String y=d+"";
       map1.put(x+""+y, true);
   }
   for(int i=0 ;i<b;i++){
       if(arr[p[i].f]!=0){
          map2.put(arr[p[i].f]+""+p[i].s,true);
       }
       arr[p[i].s]=p[i].f;
   }
   boolean t=true;
   for (Map.Entry<String, Boolean> entry : map2.entrySet())
{ if(map1.get(entry.getKey())==null){
    t=false;break;
}

}
   if(t)
         System.out.println("YES");
   else
         System.out.println("NO");

 }
 static class reader{
      BufferedReader read ;
      StringTokenizer tok;
      public reader(InputStream stream){
          read= new BufferedReader(new InputStreamReader(stream));
          tok=null;

      }
       String next()throws Exception{

          while(tok==null||!tok.hasMoreElements()){
              tok= new StringTokenizer(read.readLine());

          }
          return tok.nextToken();
      }

       int nextInt()throws Exception{
           return Integer.parseInt(next());

       }
    }

    }


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
import java.util.HashMap;
public class JavaApplication1{
      static  class pair{
     int f, s;
     pair(int x,int y){
      f=x;s=y;
     }
    }
    static boolean t= true;
    static ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();
    static boolean vis[] = new boolean[150001];
    static HashMap<String ,Boolean> map= new HashMap<String,Boolean>();
    public static void dfs(int x){
        vis[x]=true;
        for(int i= 0; i<list.get(x).size();i++){
            int y=list.get(x).get(i);String g="";String h="";
            for(int j= 0;j<list.get(y).size();j++){
                g =x+"";g+=list.get(y).get(j);h=list.get(y).get(j)+"";h+=x;

                if(map.get(g)==null||map.get(h)==null){
                    t=false;return;}
                if(map.get(g)==true||map.get(h)==true){
                    continue;}
                else{
                   t=false;return;
                }
            }
        }
        for(int i=0;i<list.get(x).size();i++)
            if(!vis[list.get(x).get(i)])
            dfs(list.get(x).get(i));
 }
 public static void main(String [] args)throws Exception{
  reader in = new reader(System.in);
   int  a=in.nextInt();int  b=in.nextInt();

      for(int i=0;i<150000;i++)
          list.add(new ArrayList<Integer>());
      for(int i=0 ; i<b;i++){
          int x=in.nextInt();int y=in.nextInt();

         map.put(x+""+y, true);map.put(x+""+x, true);map.put(y+""+y, true);map.put(y+""+x, true);
          list.get(x).add(y);
          list.get(y).add(x);}
      for(int i=0 ;i<150000;i++){
          if(!vis[i])
              dfs(i);
      }

         if(t)
             System.out.println("YES");
         else
             System.out.println("NO");

 }
 static class reader{
      BufferedReader read ;
      StringTokenizer tok;
      public reader(InputStream stream){
          read= new BufferedReader(new InputStreamReader(stream));
          tok=null;

      }
       String next()throws Exception{

          while(tok==null||!tok.hasMoreElements()){
              tok= new StringTokenizer(read.readLine());

          }
          return tok.nextToken();
      }

       int nextInt()throws Exception{
           return Integer.parseInt(next());

       }
    }

    }


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Map;
import java.io.*;
import java.util.InputMismatchException;
public class SwapWords {
static class pair{
 int f,s;
 pair(int x,int y){
  f=x;s=y;
 }
}

    public static void main(String[] args)throws Exception {
      FasterScanner in = new FasterScanner();
      int n =in.nextInt();int m =in.nextInt();
      ArrayList<ArrayList<Integer>> arr = new ArrayList<ArrayList<Integer>>();
      HashMap<String,Boolean> map1 = new HashMap<String,Boolean>();
      HashMap<String,Boolean> map2 = new HashMap<String,Boolean>();
      pair []  p= new pair[m];
     for(int i= 0;i<n+1;i++)
          arr.add(new ArrayList<Integer>());

   for(int i=0;i<m;i++){
       int c=in.nextInt();int d=in.nextInt();
       p[i]=new pair(c,d);
       arr.get(c).add(d);
       String x=c+"";String y=d+"";
       map1.put(" ", true);

   }

   for(int i= 0;i<m;i++){

       for(int j=0;j<arr.get(p[i].s).size();j++){

           map2.put(p[i].f+" "+arr.get(p[i].s).get(j),true);
           map2.put(arr.get(p[i].s).get(j)+" "+p[i].f,true);
       }
       }
   boolean t=true;
    for (Map.Entry<String, Boolean> entry : map2.entrySet())
{ if(map1.get(entry.getKey())==null){
            t=false;break;
}

}

   if(t)
         System.out.println("YES");
   else
         System.out.println("NO");

    }
   static   class FasterScanner {
	private InputStream mIs;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;

	public FasterScanner() {
		this(System.in);
	}

	public FasterScanner(InputStream is) {
		mIs = is;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = mIs.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public String nextLine() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

	public String nextString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long nextLong() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public int nextInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public boolean isEndOfLine(int c) {
		return c == '\n' || c == '\r' || c == -1;
	}

}}


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Map;
public class SwapWords {
static class pair{
 int f,s;
 pair(int x,int y){
  f=x;s=y;
 }
}

    public static void main(String[] args)throws Exception {
      reader in = new reader(System.in);
      int n =in.nextInt();int m =in.nextInt();
      ArrayList<ArrayList<Integer>> arr = new ArrayList<ArrayList<Integer>>();
      HashMap<String,Boolean> map1 = new HashMap<String,Boolean>();
      HashMap<String,Boolean> map2 = new HashMap<String,Boolean>();
      pair []  p= new pair[m];
      for(int i= 0;i<n+1;i++)
          arr.add(new ArrayList<Integer>());
   for(int i=0;i<m;i++){
       int c=in.nextInt();int d=in.nextInt();
       p[i]=new pair(c,d);
       arr.get(c).add(d);

       map1.put(c+" "+d, true);
       map1.put(d+" "+c,true);
   }
   for(int i= 0;i<m;i++){
       for(int j=0;j<arr.get(p[i].s).size();j++){
           map2.put(p[i].f+" "+arr.get(p[i].s).get(j),true);
           map2.put(arr.get(p[i].s).get(j)+" "+p[i].f,true);
       }
       }
   boolean t=true;
    for (Map.Entry<String, Boolean> entry : map2.entrySet())
{ if(map1.get(entry.getKey())==null){
            t=false;break;
}

}

   if(t)
         System.out.println("YES");
   else
         System.out.println("NO");

    }
     static class reader{
      BufferedReader read ;
      StringTokenizer tok;
      public reader(InputStream stream){
          read= new BufferedReader(new InputStreamReader(stream));
          tok=null;

      }
       String next()throws Exception{

          while(tok==null||!tok.hasMoreElements()){
              tok= new StringTokenizer(read.readLine());

          }
          return tok.nextToken();
      }

       int nextInt()throws Exception{
           return Integer.parseInt(next());

       }
    }
}


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
import java.util.HashMap;
public class JavaApplication1{
      static  class pair{
     int f, s;
     pair(int x,int y){
      f=x;s=y;
     }
    }
    static boolean t= true;
    static ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();
    static boolean vis[] = new boolean[150001];
    static int  arr[][];
    public static void dfs(int x){
        vis[x]=true;
        for(int i= 0; i<list.get(x).size();i++){
            int y=list.get(x).get(i);
            for(int j= 0;j<list.get(y).size();j++){
                if(arr[list.get(y).get(j)][x]==1||arr[x][list.get(y).get(j)]==1){
                    continue;}
                else{
                   t=false;return;
                }
            }
        }
        for(int i=0;i<list.get(x).size();i++)
            if(!vis[list.get(x).get(i)])
            dfs(list.get(x).get(i));
 }
 public static void main(String [] args)throws Exception{
  reader in = new reader(System.in);
   int  a=in.nextInt();int  b=in.nextInt();
      arr = new int [a][a];
      for(int i=0;i<150000;i++)
          list.add(new ArrayList<Integer>());
      for(int i=0 ; i<b;i++){
          int x=in.nextInt();int y=in.nextInt();
          x--;y--;
          arr[x][y]=1;arr[x][x]=1;arr[y][y]=1;
          list.get(x).add(y);
          list.get(y).add(x);}
      for(int i=0 ;i<150000;i++){
          if(!vis[i])
              dfs(i);
      }

         if(t)
             System.out.println("YES");
         else
             System.out.println("NO");

 }
 static class reader{
      BufferedReader read ;
      StringTokenizer tok;
      public reader(InputStream stream){
          read= new BufferedReader(new InputStreamReader(stream));
          tok=null;

      }
       String next()throws Exception{

          while(tok==null||!tok.hasMoreElements()){
              tok= new StringTokenizer(read.readLine());

          }
          return tok.nextToken();
      }

       int nextInt()throws Exception{
           return Integer.parseInt(next());

       }
    }

    }


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
public class FrequancyArray {
    static  class pair{
     int f, s;
     pair(int x,int y){
      f=x;s=y;
     }
    }

 public static void main(String [] args)throws Exception{
      reader in = new reader(System.in);
      int  a=in.nextInt();int  b=in.nextInt();
      pair [] p= new pair[b];
      int arr[][]= new int[Math.max(a,b)+1][Math.max(a,b)+1];

      for(int i= 0; i<b;i++){
         int x=in.nextInt();int y=in.nextInt();

         if(x<y){p[i]= new pair(x,y);
       arr[x][y]=1;}
         else{arr[y][x]=1;
            p[i]= new pair(y,x); }
      }
      boolean t= false;int count=0;
      for(int i=0 ;i<b-1;i++){
          int x=p[i].f;int y=p[i].s;int m=p[i+1].f;int n=p[i+1].s;

          if(y==m&&arr[x][n]!=1){
           t=true;   break;
          }
      }
      if(t){
         for(int i=0 ;i<b-1;i++){
          int x=p[i].f;int y=p[i].s;int m=p[i+1].f;int n=p[i+1].s;
          if(y==m&&arr[x][n]!=1){
           count++;
          }
      }
         if(count==b)
              System.out.println("yes");
         else
              System.out.println("no");

      }
      else
          System.out.println("yes");

 }
 static class reader{
      BufferedReader read ;
      StringTokenizer tok;
      public reader(InputStream stream){
          read= new BufferedReader(new InputStreamReader(stream));
          tok=null;

      }
       String next()throws Exception{

          while(tok==null||!tok.hasMoreElements()){
              tok= new StringTokenizer(read.readLine());

          }
          return tok.nextToken();
      }

       int nextInt()throws Exception{
           return Integer.parseInt(next());

       }
    }

    }


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Map;
import java.io.*;
import java.util.InputMismatchException;
public class SwapWords {
static class pair{
 int f,s;
 pair(int x,int y){
  f=x;s=y;
 }
}

    public static void main(String[] args)throws Exception {
      FasterScanner in = new FasterScanner();
      int n =in.nextInt();int m =in.nextInt();
      ArrayList<ArrayList<Integer>> arr = new ArrayList<ArrayList<Integer>>();
      HashMap<String,Boolean> map1 = new HashMap<String,Boolean>();
      HashMap<String,Boolean> map2 = new HashMap<String,Boolean>();
      pair []  p= new pair[m];
     for(int i= 0;i<n+1;i++)
          arr.add(new ArrayList<Integer>());

   for(int i=0;i<m;i++){
       int c=in.nextInt();int d=in.nextInt();
       p[i]=new pair(c,d);
       arr.get(c).add(d);

       map1.put(c+" "+d, true);

   }

   for(int i= 0;i<m;i++){

       for(int j=0;j<arr.get(p[i].s).size();j++){

           map2.put(p[i].f+" "+arr.get(p[i].s).get(j),true);
           map2.put(arr.get(p[i].s).get(j)+" "+p[i].f,true);
       }
       }
   boolean t=true;
    for (Map.Entry<String, Boolean> entry : map2.entrySet())
{ if(map1.get(entry.getKey())==null){
            t=false;break;
}

}

   if(t)
         System.out.println("YES");
   else
         System.out.println("NO");

    }
   static   class FasterScanner {
	private InputStream mIs;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;

	public FasterScanner() {
		this(System.in);
	}

	public FasterScanner(InputStream is) {
		mIs = is;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = mIs.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public String nextLine() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

	public String nextString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long nextLong() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public int nextInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public boolean isEndOfLine(int c) {
		return c == '\n' || c == '\r' || c == -1;
	}

}}


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Map;
import java.io.*;
import java.util.InputMismatchException;
public class SwapWords {
static class pair{
 int f,s;
 pair(int x,int y){
  f=x;s=y;
 }
}

    public static void main(String[] args)throws Exception {
      reader in = new reader(System.in);
      int n=in.nextInt();int m =in.nextInt();
      UF ds= new UF(n);
      int ans[] = new int[n+1];
      for(int i=0;i<n+1;i++)
          ans[i]=1;
      pair[] p = new pair[m];
      for(int i= 0;i<m;i++){
          int a=in.nextInt();
          int b=in.nextInt();
          ans[a]++;ans[b]++;
          p[i]= new pair(a,b);
          ds.union(a, b);

      }
      for(int i=0;i<n+1;i++){
        if(ds.rank[ds.parent[i]]!=0){
            ds.rank[i]=ds.rank[ds.parent[i]];
        }
      }

      boolean t= true;
      for(int i=0;i<n+1;i++)
          if(ans[i]!=ds.rank[i]){
           t=false;break;
          }

      if(t)
            System.out.println("YES");
      else
            System.out.println("NO");

    }
    static class UF {
     public int parent[];
     public int rank[];
     int count ;

    public UF(int n){
        parent = new int [n+1];
        rank = new int [n+1];
        count = n;
        for(int i= 0; i< n+1 ;i++)
        {parent[i]=i;
         rank[i]=1;
        }
    }
    public int count(){

     return count;
    }
    public int find(int p){
        while(p!=parent[p]){
            parent[p]=parent[parent[p]];
             p = parent [p];

        }
        return  p;
    }
    public void union(int i , int j){
        int x= find(i);
        int y= find(j);
        if(x==y)
            return ;
        if(rank[x]>rank[y]){
            parent[y]=x;
            rank[x]+=rank[y];
        }
        else {
            parent[x]=y;
            rank[y]+=rank[x];
        }
       count--;

    }
}
   static class reader{
      BufferedReader read ;
      StringTokenizer tok;
      public reader(InputStream stream){
          read= new BufferedReader(new InputStreamReader(stream));
          tok=null;

      }
       String next()throws Exception{

          while(tok==null||!tok.hasMoreElements()){
              tok= new StringTokenizer(read.readLine());

          }
          return tok.nextToken();
      }

       int nextInt()throws Exception{
           return Integer.parseInt(next());

       }
    }

}


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Map;
public class SwapWords {
static class pair{
 int f,s;
 pair(int x,int y){
  f=x;s=y;
 }
}

    public static void main(String[] args)throws Exception {
      reader in = new reader(System.in);
      int n =in.nextInt();int m =in.nextInt();
      ArrayList<ArrayList<Integer>> arr = new ArrayList<ArrayList<Integer>>();
      HashMap<String,Boolean> map1 = new HashMap<String,Boolean>();
      HashMap<String,Boolean> map2 = new HashMap<String,Boolean>();
      pair []  p= new pair[m];
      for(int i= 0;i<n+1;i++)
          arr.add(new ArrayList<Integer>());
   for(int i=0;i<m;i++){
       int c=in.nextInt();int d=in.nextInt();
       p[i]=new pair(c,d);
       arr.get(c).add(d);
       String x=c+"";String y=d+"";
       map1.put(x+" "+y, true);
   }
   for(int i= 0;i<m;i++){
       for(int j=0;j<arr.get(p[i].s).size();j++){
           map2.put(p[i].f+" "+arr.get(p[i].s).get(j),true);
       }
       }
   boolean t=true;
    for (Map.Entry<String, Boolean> entry : map2.entrySet())
{ if(map1.get(entry.getKey())==null){
           t=false;break;
}

}

   if(t)
         System.out.println("YES");
   else
         System.out.println("NO");

    }
     static class reader{
      BufferedReader read ;
      StringTokenizer tok;
      public reader(InputStream stream){
          read= new BufferedReader(new InputStreamReader(stream));
          tok=null;

      }
       String next()throws Exception{

          while(tok==null||!tok.hasMoreElements()){
              tok= new StringTokenizer(read.readLine());

          }
          return tok.nextToken();
      }

       int nextInt()throws Exception{
           return Integer.parseInt(next());

       }
    }
}