#include "bits/stdc++.h"
using namespace std;
struct UF {
int N;
std::vector<int> e;
void init(int n){
e.assign(n,-1);
}
bool sameSet(int a, int b) { return find(a) == find(b); }
int size(int x) { return -e[find(x)]; }
int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
bool join(int a, int b) {
a = find(a), b = find(b);
if (a == b) return false;
if (e[a] > e[b]) swap(a, b);
e[a] += e[b]; e[b] = a;
return true;
}
};
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m; cin>>n>>m;
UF dsu_for_graph_one, dsu_for_graph_two;
dsu_for_graph_one.init(n), dsu_for_graph_two.init(n);
vector<int>degreeSeq_firstGraph(n), degreeSeq_secondGraph(n);
vector<int>componentSize_firstGraph, componentSize_secondGraph;
for(int i = 0;i<m;i++){
int a, b; cin>>a>>b;
--a, --b;
degreeSeq_firstGraph[a]++, degreeSeq_firstGraph[b]++;
dsu_for_graph_one.join(a, b);
}
for(int i = 0;i<m;i++){
int a, b; cin>>a>>b;
--a, --b;
degreeSeq_secondGraph[a]++, degreeSeq_secondGraph[b]++;
dsu_for_graph_two.join(a, b);
}
for(int i = 0;i<n;i++){
componentSize_firstGraph.push_back(dsu_for_graph_one.size(i));
componentSize_secondGraph.push_back(dsu_for_graph_two.size(i));
}
sort(degreeSeq_firstGraph.begin(), degreeSeq_firstGraph.end());
sort(degreeSeq_secondGraph.begin(), degreeSeq_secondGraph.end());
sort(componentSize_firstGraph.begin(), componentSize_firstGraph.end());
sort(componentSize_secondGraph.begin(), componentSize_secondGraph.end());
if(degreeSeq_firstGraph == degreeSeq_secondGraph && componentSize_firstGraph == componentSize_secondGraph){
cout<<"Yes";
}
else cout<<"No";
}
I2luY2x1ZGUgImJpdHMvc3RkYysrLmgiCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IFVGIHsKICAgIGludCBOOwogICAgc3RkOjp2ZWN0b3I8aW50PiBlOwogICAgdm9pZCBpbml0KGludCBuKXsKICAgICAgICB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