#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// oset Operations: order_of_key(k) -> Number of elements strictly smaller than k, find_by_order(k) -> kth element in the set

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vd vector<double>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvb vector<vb>
#define vs vector<string>
#define pull pair<ull, ull>
#define F first
#define S second
#define m_p make_pair

const long double PI = 3.141592653589793238462643383279502884197169399;

template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}
template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res.push_back(static_cast<char>('0' + v[i]));
    }
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifndef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 0
#endif

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

const int mxN = 1e6+10;

struct BIT{
	int n;
	vll a;

	void init(int n){
		a = vll(n+1, 0);
		this->n = n;
	}

	void update(int loc, ll x){
		if(loc <= 0)return;
		while(loc <= n){
			a[loc] += x;
			loc += (loc & (-loc));
		}
	}

	ll query(int loc){
		ll sum=0;
		while(loc > 0){
//			debug(loc);
			sum += a[loc];
			loc -= (loc & (-loc));
		}
		return sum;
	}

	ll query(int l, int r){
		return query(r) - query(l-1);
	}
	// 1 based - indexing
};

void solve(){
	int n;
	cin >> n;

	vpii v(n);
	for(pii& p : v)cin >> p.F >> p.S;

	sort(all(v));

	BIT bit;
	bit.init(mxN);

	ll edges=0;
	for(pii p : v){
		int greaterThanStart = bit.query(p.F, 2*n);
		int greaterThanEnd = bit.query(p.S+1, 2*n);
//		debug(greaterThanStart, greaterThanEnd);
		edges += (greaterThanStart - greaterThanEnd);

		bit.update(p.S, 1);
	}
//	debug(edges);
	if(edges == n-1)cout << "YES";
	else cout << "NO";
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cout << fixed << setprecision(10);

	int tt=1;
//	cin >> tt;

	while(tt--){
		solve();
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// oset Operations: order_of_key(k) -> Number of elements strictly smaller than k, find_by_order(k) -> kth element in the set

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vd vector<double>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvb vector<vb>
#define vs vector<string>
#define pull pair<ull, ull>
#define F first
#define S second
#define m_p make_pair

const long double PI = 3.141592653589793238462643383279502884197169399;

template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}
template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res.push_back(static_cast<char>('0' + v[i]));
    }
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifndef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 0
#endif

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

const int mxN = 1e6+2;

struct BIT{
	int n;
	vll a;

	void init(int n){
		a = vll(n+1, 0);
		this->n = n;
	}

	void update(int loc, ll x){
		if(loc <= 0)return;
		while(loc <= n){
			a[loc] += x;
			loc += (loc & (-loc));
		}
	}

	ll query(int loc){
		ll sum=0;
		while(loc > 0){
			sum += a[loc];
			loc -= (loc & (-loc));
		}
		return sum;
	}

	ll query(int l, int r){
		return query(r) - query(l-1);
	}
	// 1 based - indexing
};

void solve(){
	int n;
	cin >> n;

	vpii v(n);
	for(pii& p : v)cin >> p.F >> p.S;

	sort(all(v));

	BIT bit;
	bit.init(2*n+1);

	ll edges=0;
	for(pii p : v){
		int greaterThanStart = bit.query(p.F, 2*n);
		int greaterThanEnd = bit.query(p.S, 2*n);

		edges += (greaterThanStart - greaterThanEnd);

		bit.update(p.S, 1);
	}

	if(edges == n-1)cout << "YES";
	else cout << "NO";
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cout << fixed << setprecision(10);

	int tt=1;
//	cin >> tt;

	while(tt--){
		solve();
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// oset Operations: order_of_key(k) -> Number of elements strictly smaller than k, find_by_order(k) -> kth element in the set

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vd vector<double>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvb vector<vb>
#define vs vector<string>
#define pull pair<ull, ull>
#define F first
#define S second
#define m_p make_pair

const long double PI = 3.141592653589793238462643383279502884197169399;

template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}
template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res.push_back(static_cast<char>('0' + v[i]));
    }
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifndef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 0
#endif

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

const int mxN = 1e6+2;

struct BIT{
	int n;
	vll a;

	void init(int n){
		a = vll(n+1, 0);
		this->n = n;
	}

	void update(int loc, ll x){
		if(loc <= 0)return;
		while(loc <= n){
			a[loc] += x;
			loc += (loc & (-loc));
		}
	}

	ll query(int loc){
		ll sum=0;
		while(loc > 0){
//			debug(loc);
			sum += a[loc];
			loc -= (loc & (-loc));
		}
		return sum;
	}

	ll query(int l, int r){
		return query(r) - query(l-1);
	}
	// 1 based - indexing
};

void solve(){
	int n;
	cin >> n;

	vpii v(n);
	for(pii& p : v)cin >> p.F >> p.S;

	sort(all(v));

	BIT bit;
	bit.init(2*n+3);

	ll edges=0;
	for(pii p : v){
		int greaterThanStart = bit.query(p.F, 2*n);
		int greaterThanEnd = bit.query(p.S+1, 2*n);
//		debug(greaterThanStart, greaterThanEnd);
		edges += (greaterThanStart - greaterThanEnd);

		bit.update(p.S, 1);
	}
//	debug(edges);
	if(edges == n-1)cout << "YES";
	else cout << "NO";
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cout << fixed << setprecision(10);

	int tt=1;
//	cin >> tt;

	while(tt--){
		solve();
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// oset Operations: order_of_key(k) -> Number of elements strictly smaller than k, find_by_order(k) -> kth element in the set

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vd vector<double>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvb vector<vb>
#define vs vector<string>
#define pull pair<ull, ull>
#define F first
#define S second
#define m_p make_pair

const long double PI = 3.141592653589793238462643383279502884197169399;

template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}
template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res.push_back(static_cast<char>('0' + v[i]));
    }
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifndef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 0
#endif

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

const int mxN = 1e6+2;

struct BIT{
	int n;
	vll a;

	void init(int n){
		a = vll(n+1, 0);
		this->n = n;
	}

	void update(int loc, ll x){
		if(loc <= 0)return;
		while(loc <= n){
			a[loc] += x;
			loc += (loc & (-loc));
		}
	}

	ll query(int loc){
		ll sum=0;
		while(loc > 0){
			sum += a[loc];
			loc -= (loc & (-loc));
		}
		return sum;
	}

	ll query(int l, int r){
		return query(r) - query(l-1);
	}
	// 1 based - indexing
};

void solve(){
	int n;
	cin >> n;

	vpii v(n);
	for(pii& p : v)cin >> p.F >> p.S;

	sort(all(v));

	BIT bit;
	bit.init(2*n+1);

	ll edges=0;
	for(pii p : v){
		int greaterThanStart = bit.query(p.F, 2*n);
		int greaterThanEnd = bit.query(p.S+1, 2*n);

		edges += (greaterThanStart - greaterThanEnd);

		bit.update(p.S, 1);
	}

	if(edges == n-1)cout << "YES";
	else cout << "NO";
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cout << fixed << setprecision(10);

	int tt=1;
//	cin >> tt;

	while(tt--){
		solve();
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// oset Operations: order_of_key(k) -> Number of elements strictly smaller than k, find_by_order(k) -> kth element in the set

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vd vector<double>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvb vector<vb>
#define vs vector<string>
#define pull pair<ull, ull>
#define F first
#define S second
#define m_p make_pair

const long double PI = 3.141592653589793238462643383279502884197169399;

template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}
template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res.push_back(static_cast<char>('0' + v[i]));
    }
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifndef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 0
#endif

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

const int mxN = 1e6+10;

vvi g;
vb vis;

void dfs(int node){
	vis[node] = 1;
	for(int to : g[node]){
		if(!vis[to]){
			dfs(to);
		}
	}
}

void solve(){
	int n;
	cin >> n;

	vpii v(n);
	for(pii& p : v)cin >> p.F >> p.S;

	set<vi> s;
	for(int i=0 ; i<n ; ++i){
		s.insert({v[i].F, 1, i});
		s.insert({v[i].S, -1, i});
	}

//	debug(s);
	g = vvi(n);

	int cnt=0;
	set<vi> inContention;
	for(auto it : s){
//		debug(it);
//		debug(inContention);
		if(it[1] == -1){
			inContention.erase(inContention.find({it[0], it[2]}));
		}
		else{
			for(auto it2 : inContention){
				if(v[it[2]].S < it2[0])break;
				++cnt;
				g[it2[1]].pb(it[2]);
				g[it[2]].pb(it2[1]);
			}

			inContention.insert({v[it[2]].S, it[2]});
		}
//		debug(cnt);
		if(cnt > n-1)break;
	}

	vis = vb(n, 0);
	dfs(0);

	if(cnt == n-1 && accumulate(all(vis), 0) == n){
		cout << "YES";
		return;
	}

	cout << "NO";
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cout << fixed << setprecision(10);

	int tt=1;
//	cin >> tt;

	while(tt--){
		solve();
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#ifndef orewabaka
    #define f first
    #define s second
    #define minna(a) a.begin(), a.end()
    #define ovse(a) a.rbegin(), a.rend()
    #define pb push_back
    #define endl aut '\n'
    #define ar vector
    #define var auto
    #define rand() (((rand()<<15)+rand())&INT32_MAX)
    #define ain cin,
    #define aut cout,
    #define $(a) (i64)a.size()
    #define in insert
    #define fusrodah return
    #define mp make_pair
    #define rep(i, n) for(i64 i=0;i<(n);i++)
    #define rep1(i, n) for(i64 i=1;i<(n);i++)
    #define fro2(i, a, b) for(i64 i=(a);i<(b);i++)
    #define elif else if

    typedef int i32;
    typedef unsigned u32;
    typedef long long i64;
    typedef unsigned long long u64;
    typedef pair<i32, i32> p32;
    typedef pair<i64, i64> p64;
    typedef double lf;
    typedef long double ld;
    typedef tree<i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

    namespace shyutsuryoku{
        const i32 STRSZ=3e6+13;
        char inbufer[STRSZ];
        inline void cscan(string& i){
            i32 c=getc(stdin), cnt=0;while(c<=32)c=getc(stdin);
            while(c>32)*(inbufer+cnt)=c,c=getc(stdin),++cnt;
            *(cnt+inbufer)=0;i=inbufer;
        }
        inline void cprint(string& i){
            char *s=new char[i.size()+1];
            strcpy(s, i.c_str());
            while(*s)putchar(*s), s++;
        }
        inline void cprint(const char*& i){
            i32 cnt=0;
            while(*(i+cnt))putc(*(i+cnt), stdout),cnt++;
        }
        inline void cscan(i32&i){
            i=0;i32 c=getc(stdin), b=0;while(c<=32)c=getc(stdin);if(c=='-')b=1, c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
            if(b)i=-i;
        }
        inline void cprint(i32 i){
            if(i<0)putc('-',stdout),i=-i;
            i32 sz=0;char ans[13];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(i64&i){
            i=0;i32 c=getc(stdin), b=1;while(c<=32)c=getc(stdin);if(c=='-')b=-1,c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
            i*=b;
        }
        inline void cprint(i64 i){
            if(i<0)putc('-',stdout),i=-i;
            i32 sz=0;char ans[21];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(u32&i){
            i=0;i32 c=getc(stdin);while(c<=32)c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
        }
        inline void cprint(u32 i){
            i32 sz=0;char ans[12];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(u64&i){
            i=0;i32 c=getc(stdin);while(c<=32)c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
        }
        inline void cprint(u64 i){
            i32 sz=0;char ans[21];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(lf&i){
            scanf("%lf", &i);
        }
        inline void cprint(lf i){
            printf("%.20lf", i);
        }
        inline void cprint(char i){
            putc(i, stdout);
        }
        inline void cscan(char&i){
            i32 b=getc(stdin);
            while(b<=32)b=getc(stdin);
            i=b;
        }
        template<class T, class K>inline void cscan(pair<T, K>& i){
            cscan(i.f);cscan(i.s);
        }
        template<class T, class K>inline void cprint(pair<T, K>& i){
            cprint(i.f);cprint(' ');cprint(i.s);cprint('\n');
        }
        template<class T>inline void cscan(ar<T>& i){
            for(var& j:i)cscan(j);
        }
        template<class T>inline void cprint(ar<T>& i){
            for(var& j:i)cprint(j), cprint(' ');
        }
        template<class T>inline void cprint(ar<ar<T> >& i){
            for(var& j:i)cprint(j), cprint('\n');
        }
    }
    template<class T>ostream &operator,(ostream &os, T v){
        shyutsuryoku::cprint(v);//cprint(' ');
        return os;
    }
    template<class T>istream &operator,(istream &is, T &v){
        shyutsuryoku::cscan(v);
        return is;
    }
#endif

void misaka_mikoto_is_the_best_girl_ever();

i32 main(){
    #ifdef tavan_sersyv
        freopen(".in","r",stdin);
        freopen(".out","w",stdout);
    #endif
        srand(time(0));
        misaka_mikoto_is_the_best_girl_ever();
    #ifdef tavan_sersyv
        aut '\n', (lf)clock()/CLOCKS_PER_SEC, " 秒\n";
    #endif
    fusrodah 0;
}
ar<i32> g[(i32)1e6+1];
i32 us[(i32)1e6+1];
void _1(i32 v){
    us[v]=1;
    for(i32 i:g[v])if(!us[i])_1(i);
}
void misaka_mikoto_is_the_best_girl_ever(){
    i32 n, ed=0;
    ain n;
    ar<i32> ln(2*n+1);
    map<i32, i32> rg;
    for(i32 i=1;i<=n;i++){
        i32 l, r;
        ain l, r;
        ln[l]=r;
        rg[r]=i;
    }
    ordered_set lel;
    for(i32 i=1;i<=n+n;i++){
        if(ln[i]){
            ed+=lel.order_of_key(ln[i]);
            lel.in(ln[i]);
        }else{
            lel.erase(i);
        }
    }
    if(ed!=n-1){
        aut "NO";
        return;
    }
    for(i32 i=1;i<=n+n;i++){
        if(ln[i]){
            for(i32 j:lel){
                if(j>=ln[i])break;
                g[rg[j]].pb(rg[ln[i]]);
                g[rg[ln[i]]].pb(rg[j]);
            }
            lel.in(ln[i]);
        }else{
            lel.erase(i);
        }
    }
    _1(1);
    for(i32 i=1;i<=n;i++){
        if(!us[i]){
            aut "NO";
            return;
        }
    }
    aut "YES";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#ifndef orewabaka
    #define f first
    #define s second
    #define minna(a) a.begin(), a.end()
    #define ovse(a) a.rbegin(), a.rend()
    #define pb push_back
    #define endl aut '\n'
    #define ar vector
    #define var auto
    #define rand() (((rand()<<15)+rand())&INT32_MAX)
    #define ain cin,
    #define aut cout,
    #define $(a) (i64)a.size()
    #define in insert
    #define fusrodah return
    #define mp make_pair
    #define rep(i, n) for(i64 i=0;i<(n);i++)
    #define rep1(i, n) for(i64 i=1;i<(n);i++)
    #define fro2(i, a, b) for(i64 i=(a);i<(b);i++)
    #define elif else if

    typedef int i32;
    typedef unsigned u32;
    typedef long long i64;
    typedef unsigned long long u64;
    typedef pair<i32, i32> p32;
    typedef pair<i64, i64> p64;
    typedef double lf;
    typedef long double ld;
    typedef tree<i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

    namespace shyutsuryoku{
        const i32 STRSZ=3e6+13;
        char inbufer[STRSZ];
        inline void cscan(string& i){
            i32 c=getc(stdin), cnt=0;while(c<=32)c=getc(stdin);
            while(c>32)*(inbufer+cnt)=c,c=getc(stdin),++cnt;
            *(cnt+inbufer)=0;i=inbufer;
        }
        inline void cprint(string& i){
            char *s=new char[i.size()+1];
            strcpy(s, i.c_str());
            while(*s)putchar(*s), s++;
        }
        inline void cprint(const char*& i){
            i32 cnt=0;
            while(*(i+cnt))putc(*(i+cnt), stdout),cnt++;
        }
        inline void cscan(i32&i){
            i=0;i32 c=getc(stdin), b=0;while(c<=32)c=getc(stdin);if(c=='-')b=1, c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
            if(b)i=-i;
        }
        inline void cprint(i32 i){
            if(i<0)putc('-',stdout),i=-i;
            i32 sz=0;char ans[13];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(i64&i){
            i=0;i32 c=getc(stdin), b=1;while(c<=32)c=getc(stdin);if(c=='-')b=-1,c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
            i*=b;
        }
        inline void cprint(i64 i){
            if(i<0)putc('-',stdout),i=-i;
            i32 sz=0;char ans[21];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(u32&i){
            i=0;i32 c=getc(stdin);while(c<=32)c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
        }
        inline void cprint(u32 i){
            i32 sz=0;char ans[12];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(u64&i){
            i=0;i32 c=getc(stdin);while(c<=32)c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
        }
        inline void cprint(u64 i){
            i32 sz=0;char ans[21];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(lf&i){
            scanf("%lf", &i);
        }
        inline void cprint(lf i){
            printf("%.20lf", i);
        }
        inline void cprint(char i){
            putc(i, stdout);
        }
        inline void cscan(char&i){
            i32 b=getc(stdin);
            while(b<=32)b=getc(stdin);
            i=b;
        }
        template<class T, class K>inline void cscan(pair<T, K>& i){
            cscan(i.f);cscan(i.s);
        }
        template<class T, class K>inline void cprint(pair<T, K>& i){
            cprint(i.f);cprint(' ');cprint(i.s);cprint('\n');
        }
        template<class T>inline void cscan(ar<T>& i){
            for(var& j:i)cscan(j);
        }
        template<class T>inline void cprint(ar<T>& i){
            for(var& j:i)cprint(j), cprint(' ');
        }
        template<class T>inline void cprint(ar<ar<T> >& i){
            for(var& j:i)cprint(j), cprint('\n');
        }
    }
    template<class T>ostream &operator,(ostream &os, T v){
        shyutsuryoku::cprint(v);//cprint(' ');
        return os;
    }
    template<class T>istream &operator,(istream &is, T &v){
        shyutsuryoku::cscan(v);
        return is;
    }
#endif

void misaka_mikoto_is_the_best_girl_ever();

i32 main(){
    #ifdef tavan_sersyv
        freopen(".in","r",stdin);
        freopen(".out","w",stdout);
    #endif
        srand(time(0));
        misaka_mikoto_is_the_best_girl_ever();
    #ifdef tavan_sersyv
        aut '\n', (lf)clock()/CLOCKS_PER_SEC, " 秒\n";
    #endif
    fusrodah 0;
}
void misaka_mikoto_is_the_best_girl_ever(){
    i32 n, ed=0;
    ain n;
    ar<i32> ln(2*n+1);
    for(i32 i=1;i<=n;i++){
        i32 l, r;
        ain l, r;
        ln[l]=r;
    }
    ordered_set lel;
    for(i32 i=1;i<=n+n;i++){
        if(ln[i]){
            ed+=lel.order_of_key(ln[i]);
            lel.in(ln[i]);
        }else{
            lel.erase(i);
        }
        if(i!=n+n&&$(lel)==0){
            aut "NO";
            return;
        }
    }
    if(ed!=n-1){
        aut "NO";
        return;
    }
    aut "YES";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#ifndef orewabaka
    #define f first
    #define s second
    #define minna(a) a.begin(), a.end()
    #define ovse(a) a.rbegin(), a.rend()
    #define pb push_back
    #define endl aut '\n'
    #define ar vector
    #define var auto
    #define rand() (((rand()<<15)+rand())&INT32_MAX)
    #define ain cin,
    #define aut cout,
    #define $(a) (i64)a.size()
    #define in insert
    #define fusrodah return
    #define mp make_pair
    #define rep(i, n) for(i64 i=0;i<(n);i++)
    #define rep1(i, n) for(i64 i=1;i<(n);i++)
    #define fro2(i, a, b) for(i64 i=(a);i<(b);i++)
    #define elif else if

    typedef int i32;
    typedef unsigned u32;
    typedef long long i64;
    typedef unsigned long long u64;
    typedef pair<i32, i32> p32;
    typedef pair<i64, i64> p64;
    typedef double lf;
    typedef long double ld;
    typedef tree<i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

    namespace shyutsuryoku{
        const i32 STRSZ=3e6+13;
        char inbufer[STRSZ];
        inline void cscan(string& i){
            i32 c=getc(stdin), cnt=0;while(c<=32)c=getc(stdin);
            while(c>32)*(inbufer+cnt)=c,c=getc(stdin),++cnt;
            *(cnt+inbufer)=0;i=inbufer;
        }
        inline void cprint(string& i){
            char *s=new char[i.size()+1];
            strcpy(s, i.c_str());
            while(*s)putchar(*s), s++;
        }
        inline void cprint(const char*& i){
            i32 cnt=0;
            while(*(i+cnt))putc(*(i+cnt), stdout),cnt++;
        }
        inline void cscan(i32&i){
            i=0;i32 c=getc(stdin), b=0;while(c<=32)c=getc(stdin);if(c=='-')b=1, c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
            if(b)i=-i;
        }
        inline void cprint(i32 i){
            if(i<0)putc('-',stdout),i=-i;
            i32 sz=0;char ans[13];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(i64&i){
            i=0;i32 c=getc(stdin), b=1;while(c<=32)c=getc(stdin);if(c=='-')b=-1,c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
            i*=b;
        }
        inline void cprint(i64 i){
            if(i<0)putc('-',stdout),i=-i;
            i32 sz=0;char ans[21];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(u32&i){
            i=0;i32 c=getc(stdin);while(c<=32)c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
        }
        inline void cprint(u32 i){
            i32 sz=0;char ans[12];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(u64&i){
            i=0;i32 c=getc(stdin);while(c<=32)c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
        }
        inline void cprint(u64 i){
            i32 sz=0;char ans[21];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(lf&i){
            scanf("%lf", &i);
        }
        inline void cprint(lf i){
            printf("%.20lf", i);
        }
        inline void cprint(char i){
            putc(i, stdout);
        }
        inline void cscan(char&i){
            i32 b=getc(stdin);
            while(b<=32)b=getc(stdin);
            i=b;
        }
        template<class T, class K>inline void cscan(pair<T, K>& i){
            cscan(i.f);cscan(i.s);
        }
        template<class T, class K>inline void cprint(pair<T, K>& i){
            cprint(i.f);cprint(' ');cprint(i.s);cprint('\n');
        }
        template<class T>inline void cscan(ar<T>& i){
            for(var& j:i)cscan(j);
        }
        template<class T>inline void cprint(ar<T>& i){
            for(var& j:i)cprint(j), cprint(' ');
        }
        template<class T>inline void cprint(ar<ar<T> >& i){
            for(var& j:i)cprint(j), cprint('\n');
        }
    }
    template<class T>ostream &operator,(ostream &os, T v){
        shyutsuryoku::cprint(v);//cprint(' ');
        return os;
    }
    template<class T>istream &operator,(istream &is, T &v){
        shyutsuryoku::cscan(v);
        return is;
    }
#endif

void misaka_mikoto_is_the_best_girl_ever();

i32 main(){
    #ifdef tavan_sersyv
        freopen(".in","r",stdin);
        freopen(".out","w",stdout);
    #endif
        srand(time(0));
        misaka_mikoto_is_the_best_girl_ever();
    #ifdef tavan_sersyv
        aut '\n', (lf)clock()/CLOCKS_PER_SEC, " 秒\n";
    #endif
    fusrodah 0;
}
ar<i32> g[(i32)5e5+1];
i32 us[(i32)5e5+1], ln[(i32)1e6+1], rg[(i32)1e6+1];
void _1(i32 v){
    us[v]=1;
    for(i32 i:g[v])if(!us[i])_1(i);
}
void misaka_mikoto_is_the_best_girl_ever(){
    i32 n, ed=0;
    ain n;
    for(i32 i=1;i<=n;i++){
        i32 l, r;
        ain l, r;
        ln[l]=r;
        rg[r]=i;
    }
    ordered_set lel;
    for(i32 i=1;i<=n+n;i++){
        if(ln[i]){
            ed+=lel.order_of_key(ln[i]);
            lel.in(ln[i]);
        }else{
            lel.erase(i);
        }
    }
    if(ed!=n-1){
        aut "NO";
        return;
    }
    set<i32> lol;
    for(i32 i=1;i<=n+n;i++){
        if(ln[i]){
            for(i32 j:lol){
                if(j>=ln[i])break;
                g[rg[j]].pb(rg[ln[i]]);
                g[rg[ln[i]]].pb(rg[j]);
            }
            lol.in(ln[i]);
        }else{
            lol.erase(i);
        }
    }
    _1(1);
    for(i32 i=1;i<=n;i++){
        if(!us[i]){
            aut "NO";
            return;
        }
    }
    aut "YES";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#ifndef orewabaka
    #define f first
    #define s second
    #define minna(a) a.begin(), a.end()
    #define ovse(a) a.rbegin(), a.rend()
    #define pb push_back
    #define endl aut '\n'
    #define ar vector
    #define var auto
    #define rand() (((rand()<<15)+rand())&INT32_MAX)
    #define ain cin,
    #define aut cout,
    #define $(a) (i64)a.size()
    #define in insert
    #define fusrodah return
    #define mp make_pair
    #define rep(i, n) for(i64 i=0;i<(n);i++)
    #define rep1(i, n) for(i64 i=1;i<(n);i++)
    #define fro2(i, a, b) for(i64 i=(a);i<(b);i++)
    #define elif else if

    typedef int i32;
    typedef unsigned u32;
    typedef long long i64;
    typedef unsigned long long u64;
    typedef pair<i32, i32> p32;
    typedef pair<i64, i64> p64;
    typedef double lf;
    typedef long double ld;
    typedef tree<i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

    namespace shyutsuryoku{
        const i32 STRSZ=3e6+13;
        char inbufer[STRSZ];
        inline void cscan(string& i){
            i32 c=getc(stdin), cnt=0;while(c<=32)c=getc(stdin);
            while(c>32)*(inbufer+cnt)=c,c=getc(stdin),++cnt;
            *(cnt+inbufer)=0;i=inbufer;
        }
        inline void cprint(string& i){
            char *s=new char[i.size()+1];
            strcpy(s, i.c_str());
            while(*s)putchar(*s), s++;
        }
        inline void cprint(const char*& i){
            i32 cnt=0;
            while(*(i+cnt))putc(*(i+cnt), stdout),cnt++;
        }
        inline void cscan(i32&i){
            i=0;i32 c=getc(stdin), b=0;while(c<=32)c=getc(stdin);if(c=='-')b=1, c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
            if(b)i=-i;
        }
        inline void cprint(i32 i){
            if(i<0)putc('-',stdout),i=-i;
            i32 sz=0;char ans[13];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(i64&i){
            i=0;i32 c=getc(stdin), b=1;while(c<=32)c=getc(stdin);if(c=='-')b=-1,c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
            i*=b;
        }
        inline void cprint(i64 i){
            if(i<0)putc('-',stdout),i=-i;
            i32 sz=0;char ans[21];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(u32&i){
            i=0;i32 c=getc(stdin);while(c<=32)c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
        }
        inline void cprint(u32 i){
            i32 sz=0;char ans[12];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(u64&i){
            i=0;i32 c=getc(stdin);while(c<=32)c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
        }
        inline void cprint(u64 i){
            i32 sz=0;char ans[21];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(lf&i){
            scanf("%lf", &i);
        }
        inline void cprint(lf i){
            printf("%.20lf", i);
        }
        inline void cprint(char i){
            putc(i, stdout);
        }
        inline void cscan(char&i){
            i32 b=getc(stdin);
            while(b<=32)b=getc(stdin);
            i=b;
        }
        template<class T, class K>inline void cscan(pair<T, K>& i){
            cscan(i.f);cscan(i.s);
        }
        template<class T, class K>inline void cprint(pair<T, K>& i){
            cprint(i.f);cprint(' ');cprint(i.s);cprint('\n');
        }
        template<class T>inline void cscan(ar<T>& i){
            for(var& j:i)cscan(j);
        }
        template<class T>inline void cprint(ar<T>& i){
            for(var& j:i)cprint(j), cprint(' ');
        }
        template<class T>inline void cprint(ar<ar<T> >& i){
            for(var& j:i)cprint(j), cprint('\n');
        }
    }
    template<class T>ostream &operator,(ostream &os, T v){
        shyutsuryoku::cprint(v);//cprint(' ');
        return os;
    }
    template<class T>istream &operator,(istream &is, T &v){
        shyutsuryoku::cscan(v);
        return is;
    }
#endif

void misaka_mikoto_is_the_best_girl_ever();

i32 main(){
    #ifdef tavan_sersyv
        freopen(".in","r",stdin);
        freopen(".out","w",stdout);
    #endif
        srand(time(0));
        misaka_mikoto_is_the_best_girl_ever();
    #ifdef tavan_sersyv
        aut '\n', (lf)clock()/CLOCKS_PER_SEC, " 秒\n";
    #endif
    fusrodah 0;
}
ar<i32> g[(i32)5e5+1];
i32 us[(i32)5e5+1];
void _1(i32 v){
    us[v]=1;
    for(i32 i:g[v])if(!us[i])_1(i);
}
void misaka_mikoto_is_the_best_girl_ever(){
    i32 n, ed=0;
    ain n;
    ar<i32> ln(2*n+1);
    ar<i32> rg(2*n+1);
    for(i32 i=1;i<=n;i++){
        i32 l, r;
        ain l, r;
        ln[l]=r;
        rg[r]=i;
    }
    ordered_set lel;
    for(i32 i=1;i<=n+n;i++){
        if(ln[i]){
            ed+=lel.order_of_key(ln[i]);
            lel.in(ln[i]);
        }else{
            lel.erase(i);
        }
    }
    if(ed!=n-1){
        aut "NO";
        return;
    }
    set<i32> lol;
    for(i32 i=1;i<=n+n;i++){
        if(ln[i]){
            for(i32 j:lol){
                if(j>=ln[i])break;
                g[rg[j]].pb(rg[ln[i]]);
                g[rg[ln[i]]].pb(rg[j]);
            }
            lol.in(ln[i]);
        }else{
            lol.erase(i);
        }
    }
    _1(1);
    for(i32 i=1;i<=n;i++){
        if(!us[i]){
            aut "NO";
            return;
        }
    }
    aut "YES";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#ifndef orewabaka
    #define f first
    #define s second
    #define minna(a) a.begin(), a.end()
    #define ovse(a) a.rbegin(), a.rend()
    #define pb push_back
    #define endl aut '\n'
    #define ar vector
    #define var auto
    #define rand() (((rand()<<15)+rand())&INT32_MAX)
    #define ain cin,
    #define aut cout,
    #define $(a) (i64)a.size()
    #define in insert
    #define fusrodah return
    #define mp make_pair
    #define rep(i, n) for(i64 i=0;i<(n);i++)
    #define rep1(i, n) for(i64 i=1;i<(n);i++)
    #define fro2(i, a, b) for(i64 i=(a);i<(b);i++)
    #define elif else if

    typedef int i32;
    typedef unsigned u32;
    typedef long long i64;
    typedef unsigned long long u64;
    typedef pair<i32, i32> p32;
    typedef pair<i64, i64> p64;
    typedef double lf;
    typedef long double ld;
    typedef tree<i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

    namespace shyutsuryoku{
        const i32 STRSZ=3e6+13;
        char inbufer[STRSZ];
        inline void cscan(string& i){
            i32 c=getc(stdin), cnt=0;while(c<=32)c=getc(stdin);
            while(c>32)*(inbufer+cnt)=c,c=getc(stdin),++cnt;
            *(cnt+inbufer)=0;i=inbufer;
        }
        inline void cprint(string& i){
            char *s=new char[i.size()+1];
            strcpy(s, i.c_str());
            while(*s)putchar(*s), s++;
        }
        inline void cprint(const char*& i){
            i32 cnt=0;
            while(*(i+cnt))putc(*(i+cnt), stdout),cnt++;
        }
        inline void cscan(i32&i){
            i=0;i32 c=getc(stdin), b=0;while(c<=32)c=getc(stdin);if(c=='-')b=1, c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
            if(b)i=-i;
        }
        inline void cprint(i32 i){
            if(i<0)putc('-',stdout),i=-i;
            i32 sz=0;char ans[13];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(i64&i){
            i=0;i32 c=getc(stdin), b=1;while(c<=32)c=getc(stdin);if(c=='-')b=-1,c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
            i*=b;
        }
        inline void cprint(i64 i){
            if(i<0)putc('-',stdout),i=-i;
            i32 sz=0;char ans[21];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(u32&i){
            i=0;i32 c=getc(stdin);while(c<=32)c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
        }
        inline void cprint(u32 i){
            i32 sz=0;char ans[12];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(u64&i){
            i=0;i32 c=getc(stdin);while(c<=32)c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
        }
        inline void cprint(u64 i){
            i32 sz=0;char ans[21];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(lf&i){
            scanf("%lf", &i);
        }
        inline void cprint(lf i){
            printf("%.20lf", i);
        }
        inline void cprint(char i){
            putc(i, stdout);
        }
        inline void cscan(char&i){
            i32 b=getc(stdin);
            while(b<=32)b=getc(stdin);
            i=b;
        }
        template<class T, class K>inline void cscan(pair<T, K>& i){
            cscan(i.f);cscan(i.s);
        }
        template<class T, class K>inline void cprint(pair<T, K>& i){
            cprint(i.f);cprint(' ');cprint(i.s);cprint('\n');
        }
        template<class T>inline void cscan(ar<T>& i){
            for(var& j:i)cscan(j);
        }
        template<class T>inline void cprint(ar<T>& i){
            for(var& j:i)cprint(j), cprint(' ');
        }
        template<class T>inline void cprint(ar<ar<T> >& i){
            for(var& j:i)cprint(j), cprint('\n');
        }
    }
    template<class T>ostream &operator,(ostream &os, T v){
        shyutsuryoku::cprint(v);//cprint(' ');
        return os;
    }
    template<class T>istream &operator,(istream &is, T &v){
        shyutsuryoku::cscan(v);
        return is;
    }
#endif

void misaka_mikoto_is_the_best_girl_ever();

i32 main(){
    #ifdef tavan_sersyv
        freopen(".in","r",stdin);
        freopen(".out","w",stdout);
    #endif
        srand(time(0));
        misaka_mikoto_is_the_best_girl_ever();
    #ifdef tavan_sersyv
        aut '\n', (lf)clock()/CLOCKS_PER_SEC, " 秒\n";
    #endif
    fusrodah 0;
}
ar<i32> g[(i32)5e5+1];
i32 ln[(i32)1e6+1], rg[(i32)1e6+1];
bitset<(i32)5e5+1> us;
void _1(i32 v){
    us[v]=1;
    for(i32 i:g[v])if(!us[i])_1(i);
}
void misaka_mikoto_is_the_best_girl_ever(){
    i32 n, ed=0;
    ain n;
    for(i32 i=1;i<=n;i++){
        i32 l, r;
        ain l, r;
        ln[l]=r;
        rg[r]=i;
    }
    set<i32> lol;
    for(i32 i=1;i<=n+n;i++){
        if(ln[i]){
            for(i32 j:lol){
                if(j>=ln[i])break;
                ed++;
                if(ed>n-1){
                    aut "NO";
                    return;
                }
                g[rg[j]].pb(rg[ln[i]]);
                g[rg[ln[i]]].pb(rg[j]);
            }
            lol.in(ln[i]);
        }else{
            lol.erase(i);
        }
    }
    _1(1);
    for(i32 i=1;i<=n;i++){
        if(!us[i]){
            aut "NO";
            return;
        }
    }
    aut "YES";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#ifndef orewabaka
    #define f first
    #define s second
    #define minna(a) a.begin(), a.end()
    #define ovse(a) a.rbegin(), a.rend()
    #define pb push_back
    #define endl aut '\n'
    #define ar vector
    #define var auto
    #define rand() (((rand()<<15)+rand())&INT32_MAX)
    #define ain cin,
    #define aut cout,
    #define $(a) (i64)a.size()
    #define in insert
    #define fusrodah return
    #define mp make_pair
    #define rep(i, n) for(i64 i=0;i<(n);i++)
    #define rep1(i, n) for(i64 i=1;i<(n);i++)
    #define fro2(i, a, b) for(i64 i=(a);i<(b);i++)
    #define elif else if

    typedef int i32;
    typedef unsigned u32;
    typedef long long i64;
    typedef unsigned long long u64;
    typedef pair<i32, i32> p32;
    typedef pair<i64, i64> p64;
    typedef double lf;
    typedef long double ld;
    typedef tree<i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

    namespace shyutsuryoku{
        const i32 STRSZ=3e6+13;
        char inbufer[STRSZ];
        inline void cscan(string& i){
            i32 c=getc(stdin), cnt=0;while(c<=32)c=getc(stdin);
            while(c>32)*(inbufer+cnt)=c,c=getc(stdin),++cnt;
            *(cnt+inbufer)=0;i=inbufer;
        }
        inline void cprint(string& i){
            char *s=new char[i.size()+1];
            strcpy(s, i.c_str());
            while(*s)putchar(*s), s++;
        }
        inline void cprint(const char*& i){
            i32 cnt=0;
            while(*(i+cnt))putc(*(i+cnt), stdout),cnt++;
        }
        inline void cscan(i32&i){
            i=0;i32 c=getc(stdin), b=0;while(c<=32)c=getc(stdin);if(c=='-')b=1, c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
            if(b)i=-i;
        }
        inline void cprint(i32 i){
            if(i<0)putc('-',stdout),i=-i;
            i32 sz=0;char ans[13];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(i64&i){
            i=0;i32 c=getc(stdin), b=1;while(c<=32)c=getc(stdin);if(c=='-')b=-1,c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
            i*=b;
        }
        inline void cprint(i64 i){
            if(i<0)putc('-',stdout),i=-i;
            i32 sz=0;char ans[21];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(u32&i){
            i=0;i32 c=getc(stdin);while(c<=32)c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
        }
        inline void cprint(u32 i){
            i32 sz=0;char ans[12];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(u64&i){
            i=0;i32 c=getc(stdin);while(c<=32)c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
        }
        inline void cprint(u64 i){
            i32 sz=0;char ans[21];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(lf&i){
            scanf("%lf", &i);
        }
        inline void cprint(lf i){
            printf("%.20lf", i);
        }
        inline void cprint(char i){
            putc(i, stdout);
        }
        inline void cscan(char&i){
            i32 b=getc(stdin);
            while(b<=32)b=getc(stdin);
            i=b;
        }
        template<class T, class K>inline void cscan(pair<T, K>& i){
            cscan(i.f);cscan(i.s);
        }
        template<class T, class K>inline void cprint(pair<T, K>& i){
            cprint(i.f);cprint(' ');cprint(i.s);cprint('\n');
        }
        template<class T>inline void cscan(ar<T>& i){
            for(var& j:i)cscan(j);
        }
        template<class T>inline void cprint(ar<T>& i){
            for(var& j:i)cprint(j), cprint(' ');
        }
        template<class T>inline void cprint(ar<ar<T> >& i){
            for(var& j:i)cprint(j), cprint('\n');
        }
    }
    template<class T>ostream &operator,(ostream &os, T v){
        shyutsuryoku::cprint(v);//cprint(' ');
        return os;
    }
    template<class T>istream &operator,(istream &is, T &v){
        shyutsuryoku::cscan(v);
        return is;
    }
#endif

void misaka_mikoto_is_the_best_girl_ever();

i32 main(){
    #ifdef tavan_sersyv
        freopen(".in","r",stdin);
        freopen(".out","w",stdout);
    #endif
        srand(time(0));
        misaka_mikoto_is_the_best_girl_ever();
    #ifdef tavan_sersyv
        aut '\n', (lf)clock()/CLOCKS_PER_SEC, " 秒\n";
    #endif
    fusrodah 0;
}
ar<i32> g[(i32)1e6+1];
i32 us[(i32)1e6+1];
void _1(i32 v){
    us[v]=1;
    for(i32 i:g[v])if(!us[i])_1(i);
}
void misaka_mikoto_is_the_best_girl_ever(){
    i32 n, ed=0;
    ain n;
    ar<i32> ln(2*n+1);
    ar<i32> rg(2*n+1);
    for(i32 i=1;i<=n;i++){
        i32 l, r;
        ain l, r;
        ln[l]=r;
        rg[r]=i;
    }
    ordered_set lel;
    for(i32 i=1;i<=n+n;i++){
        if(ln[i]){
            ed+=lel.order_of_key(ln[i]);
            lel.in(ln[i]);
        }else{
            lel.erase(i);
        }
    }
    if(ed!=n-1){
        aut "NO";
        return;
    }
    set<i32> lol;
    for(i32 i=1;i<=n+n;i++){
        if(ln[i]){
            for(i32 j:lol){
                if(j>=ln[i])break;
                g[rg[j]].pb(rg[ln[i]]);
                g[rg[ln[i]]].pb(rg[j]);
            }
            lol.in(ln[i]);
        }else{
            lol.erase(i);
        }
    }
    _1(1);
    for(i32 i=1;i<=n;i++){
        if(!us[i]){
            aut "NO";
            return;
        }
    }
    aut "YES";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#ifndef orewabaka
    #define f first
    #define s second
    #define minna(a) a.begin(), a.end()
    #define ovse(a) a.rbegin(), a.rend()
    #define pb push_back
    #define endl aut '\n'
    #define ar vector
    #define var auto
    #define rand() (((rand()<<15)+rand())&INT32_MAX)
    #define ain cin,
    #define aut cout,
    #define $(a) (i64)a.size()
    #define in insert
    #define fusrodah return
    #define mp make_pair
    #define rep(i, n) for(i64 i=0;i<(n);i++)
    #define rep1(i, n) for(i64 i=1;i<(n);i++)
    #define fro2(i, a, b) for(i64 i=(a);i<(b);i++)
    #define elif else if

    typedef int i32;
    typedef unsigned u32;
    typedef long long i64;
    typedef unsigned long long u64;
    typedef pair<i32, i32> p32;
    typedef pair<i64, i64> p64;
    typedef double lf;
    typedef long double ld;
    typedef tree<i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

    namespace shyutsuryoku{
        const i32 STRSZ=3e6+13;
        char inbufer[STRSZ];
        inline void cscan(string& i){
            i32 c=getc(stdin), cnt=0;while(c<=32)c=getc(stdin);
            while(c>32)*(inbufer+cnt)=c,c=getc(stdin),++cnt;
            *(cnt+inbufer)=0;i=inbufer;
        }
        inline void cprint(string& i){
            char *s=new char[i.size()+1];
            strcpy(s, i.c_str());
            while(*s)putchar(*s), s++;
        }
        inline void cprint(const char*& i){
            i32 cnt=0;
            while(*(i+cnt))putc(*(i+cnt), stdout),cnt++;
        }
        inline void cscan(i32&i){
            i=0;i32 c=getc(stdin), b=0;while(c<=32)c=getc(stdin);if(c=='-')b=1, c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
            if(b)i=-i;
        }
        inline void cprint(i32 i){
            if(i<0)putc('-',stdout),i=-i;
            i32 sz=0;char ans[13];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(i64&i){
            i=0;i32 c=getc(stdin), b=1;while(c<=32)c=getc(stdin);if(c=='-')b=-1,c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
            i*=b;
        }
        inline void cprint(i64 i){
            if(i<0)putc('-',stdout),i=-i;
            i32 sz=0;char ans[21];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(u32&i){
            i=0;i32 c=getc(stdin);while(c<=32)c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
        }
        inline void cprint(u32 i){
            i32 sz=0;char ans[12];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(u64&i){
            i=0;i32 c=getc(stdin);while(c<=32)c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
        }
        inline void cprint(u64 i){
            i32 sz=0;char ans[21];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(lf&i){
            scanf("%lf", &i);
        }
        inline void cprint(lf i){
            printf("%.20lf", i);
        }
        inline void cprint(char i){
            putc(i, stdout);
        }
        inline void cscan(char&i){
            i32 b=getc(stdin);
            while(b<=32)b=getc(stdin);
            i=b;
        }
        template<class T, class K>inline void cscan(pair<T, K>& i){
            cscan(i.f);cscan(i.s);
        }
        template<class T, class K>inline void cprint(pair<T, K>& i){
            cprint(i.f);cprint(' ');cprint(i.s);cprint('\n');
        }
        template<class T>inline void cscan(ar<T>& i){
            for(var& j:i)cscan(j);
        }
        template<class T>inline void cprint(ar<T>& i){
            for(var& j:i)cprint(j), cprint(' ');
        }
        template<class T>inline void cprint(ar<ar<T> >& i){
            for(var& j:i)cprint(j), cprint('\n');
        }
    }
    template<class T>ostream &operator,(ostream &os, T v){
        shyutsuryoku::cprint(v);//cprint(' ');
        return os;
    }
    template<class T>istream &operator,(istream &is, T &v){
        shyutsuryoku::cscan(v);
        return is;
    }
#endif

void misaka_mikoto_is_the_best_girl_ever();

i32 main(){
    #ifdef tavan_sersyv
        freopen(".in","r",stdin);
        freopen(".out","w",stdout);
    #endif
        srand(time(0));
        misaka_mikoto_is_the_best_girl_ever();
    #ifdef tavan_sersyv
        aut '\n', (lf)clock()/CLOCKS_PER_SEC, " 秒\n";
    #endif
    fusrodah 0;
}
void misaka_mikoto_is_the_best_girl_ever(){
    i32 n, ed=0;
    ain n;
    ar<i32> ln(2*n+1);
    for(i32 i=1;i<=n;i++){
        i32 l, r;
        ain l, r;
        ln[l]=r;
    }
    ordered_set lel;
    for(i32 i=1;i<=n+n;i++){
        if(ln[i]){
            ed+=lel.order_of_key(ln[i]);
            lel.in(ln[i]);
        }else{
            lel.erase(i);
        }
    }
    if(ed!=n-1){
        aut "NO";
        return;
    }
    aut "YES";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#ifndef orewabaka
    #define f first
    #define s second
    #define minna(a) a.begin(), a.end()
    #define ovse(a) a.rbegin(), a.rend()
    #define pb push_back
    #define endl aut '\n'
    #define ar vector
    #define var auto
    #define rand() (((rand()<<15)+rand())&INT32_MAX)
    #define ain cin,
    #define aut cout,
    #define $(a) (i64)a.size()
    #define in insert
    #define fusrodah return
    #define mp make_pair
    #define rep(i, n) for(i64 i=0;i<(n);i++)
    #define rep1(i, n) for(i64 i=1;i<(n);i++)
    #define fro2(i, a, b) for(i64 i=(a);i<(b);i++)
    #define elif else if

    typedef int i32;
    typedef unsigned u32;
    typedef long long i64;
    typedef unsigned long long u64;
    typedef pair<i32, i32> p32;
    typedef pair<i64, i64> p64;
    typedef double lf;
    typedef long double ld;
    typedef tree<i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

    namespace shyutsuryoku{
        const i32 STRSZ=3e6+13;
        char inbufer[STRSZ];
        inline void cscan(string& i){
            i32 c=getc(stdin), cnt=0;while(c<=32)c=getc(stdin);
            while(c>32)*(inbufer+cnt)=c,c=getc(stdin),++cnt;
            *(cnt+inbufer)=0;i=inbufer;
        }
        inline void cprint(string& i){
            char *s=new char[i.size()+1];
            strcpy(s, i.c_str());
            while(*s)putchar(*s), s++;
        }
        inline void cprint(const char*& i){
            i32 cnt=0;
            while(*(i+cnt))putc(*(i+cnt), stdout),cnt++;
        }
        inline void cscan(i32&i){
            i=0;i32 c=getc(stdin), b=0;while(c<=32)c=getc(stdin);if(c=='-')b=1, c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
            if(b)i=-i;
        }
        inline void cprint(i32 i){
            if(i<0)putc('-',stdout),i=-i;
            i32 sz=0;char ans[13];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(i64&i){
            i=0;i32 c=getc(stdin), b=1;while(c<=32)c=getc(stdin);if(c=='-')b=-1,c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
            i*=b;
        }
        inline void cprint(i64 i){
            if(i<0)putc('-',stdout),i=-i;
            i32 sz=0;char ans[21];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(u32&i){
            i=0;i32 c=getc(stdin);while(c<=32)c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
        }
        inline void cprint(u32 i){
            i32 sz=0;char ans[12];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(u64&i){
            i=0;i32 c=getc(stdin);while(c<=32)c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
        }
        inline void cprint(u64 i){
            i32 sz=0;char ans[21];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(lf&i){
            scanf("%lf", &i);
        }
        inline void cprint(lf i){
            printf("%.20lf", i);
        }
        inline void cprint(char i){
            putc(i, stdout);
        }
        inline void cscan(char&i){
            i32 b=getc(stdin);
            while(b<=32)b=getc(stdin);
            i=b;
        }
        template<class T, class K>inline void cscan(pair<T, K>& i){
            cscan(i.f);cscan(i.s);
        }
        template<class T, class K>inline void cprint(pair<T, K>& i){
            cprint(i.f);cprint(' ');cprint(i.s);cprint('\n');
        }
        template<class T>inline void cscan(ar<T>& i){
            for(var& j:i)cscan(j);
        }
        template<class T>inline void cprint(ar<T>& i){
            for(var& j:i)cprint(j), cprint(' ');
        }
        template<class T>inline void cprint(ar<ar<T> >& i){
            for(var& j:i)cprint(j), cprint('\n');
        }
    }
    template<class T>ostream &operator,(ostream &os, T v){
        shyutsuryoku::cprint(v);//cprint(' ');
        return os;
    }
    template<class T>istream &operator,(istream &is, T &v){
        shyutsuryoku::cscan(v);
        return is;
    }
#endif

void misaka_mikoto_is_the_best_girl_ever();

i32 main(){
    #ifdef tavan_sersyv
        freopen(".in","r",stdin);
        freopen(".out","w",stdout);
    #endif
        srand(time(0));
        misaka_mikoto_is_the_best_girl_ever();
    #ifdef tavan_sersyv
        aut '\n', (lf)clock()/CLOCKS_PER_SEC, " 秒\n";
    #endif
    fusrodah 0;
}
ar<i32> g[(i32)1e6+1];
i32 us[(i32)1e6+1];
void _1(i32 v){
    us[v]=1;
    for(i32 i:g[v])if(!us[i])_1(i);
}
void misaka_mikoto_is_the_best_girl_ever(){
    i32 n, ed=0;
    ain n;
    ar<i32> ln(2*n+1);
    for(i32 i=1;i<=n;i++){
        i32 l, r;
        ain l, r;
        ln[l]=r;
    }
    ordered_set lel;
    for(i32 i=1;i<=n+n;i++){
        if(ln[i]){
            ed+=lel.order_of_key(ln[i]);
            lel.in(ln[i]);
        }else{
            lel.erase(i);
        }
    }
    if(ed!=n-1){
        aut "NO";
        return;
    }
    for(i32 i=1;i<=n+n;i++){
        if(ln[i]){
            for(i32 j:lel){
                if(j>=ln[i])break;
                g[j].pb(ln[i]);
                g[ln[i]].pb(j);
            }
            lel.in(ln[i]);
        }else{
            lel.erase(i);
        }
    }
    _1(1);
    for(i32 i=1;i<=n;i++){
        if(!us[i]){
            aut "NO";
            return;
        }
    }
    aut "YES";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#ifndef orewabaka
    #define f first
    #define s second
    #define minna(a) a.begin(), a.end()
    #define ovse(a) a.rbegin(), a.rend()
    #define pb push_back
    #define endl aut '\n'
    #define ar vector
    #define var auto
    #define rand() (((rand()<<15)+rand())&INT32_MAX)
    #define ain cin,
    #define aut cout,
    #define $(a) (i64)a.size()
    #define in insert
    #define fusrodah return
    #define mp make_pair
    #define rep(i, n) for(i64 i=0;i<(n);i++)
    #define rep1(i, n) for(i64 i=1;i<(n);i++)
    #define fro2(i, a, b) for(i64 i=(a);i<(b);i++)
    #define elif else if

    typedef int i32;
    typedef unsigned u32;
    typedef long long i64;
    typedef unsigned long long u64;
    typedef pair<i32, i32> p32;
    typedef pair<i64, i64> p64;
    typedef double lf;
    typedef long double ld;
    typedef tree<i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

    namespace shyutsuryoku{
        const i32 STRSZ=3e6+13;
        char inbufer[STRSZ];
        inline void cscan(string& i){
            i32 c=getc(stdin), cnt=0;while(c<=32)c=getc(stdin);
            while(c>32)*(inbufer+cnt)=c,c=getc(stdin),++cnt;
            *(cnt+inbufer)=0;i=inbufer;
        }
        inline void cprint(string& i){
            char *s=new char[i.size()+1];
            strcpy(s, i.c_str());
            while(*s)putchar(*s), s++;
        }
        inline void cprint(const char*& i){
            i32 cnt=0;
            while(*(i+cnt))putc(*(i+cnt), stdout),cnt++;
        }
        inline void cscan(i32&i){
            i=0;i32 c=getc(stdin), b=0;while(c<=32)c=getc(stdin);if(c=='-')b=1, c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
            if(b)i=-i;
        }
        inline void cprint(i32 i){
            if(i<0)putc('-',stdout),i=-i;
            i32 sz=0;char ans[13];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(i64&i){
            i=0;i32 c=getc(stdin), b=1;while(c<=32)c=getc(stdin);if(c=='-')b=-1,c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
            i*=b;
        }
        inline void cprint(i64 i){
            if(i<0)putc('-',stdout),i=-i;
            i32 sz=0;char ans[21];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(u32&i){
            i=0;i32 c=getc(stdin);while(c<=32)c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
        }
        inline void cprint(u32 i){
            i32 sz=0;char ans[12];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(u64&i){
            i=0;i32 c=getc(stdin);while(c<=32)c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
        }
        inline void cprint(u64 i){
            i32 sz=0;char ans[21];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(lf&i){
            scanf("%lf", &i);
        }
        inline void cprint(lf i){
            printf("%.20lf", i);
        }
        inline void cprint(char i){
            putc(i, stdout);
        }
        inline void cscan(char&i){
            i32 b=getc(stdin);
            while(b<=32)b=getc(stdin);
            i=b;
        }
        template<class T, class K>inline void cscan(pair<T, K>& i){
            cscan(i.f);cscan(i.s);
        }
        template<class T, class K>inline void cprint(pair<T, K>& i){
            cprint(i.f);cprint(' ');cprint(i.s);cprint('\n');
        }
        template<class T>inline void cscan(ar<T>& i){
            for(var& j:i)cscan(j);
        }
        template<class T>inline void cprint(ar<T>& i){
            for(var& j:i)cprint(j), cprint(' ');
        }
        template<class T>inline void cprint(ar<ar<T> >& i){
            for(var& j:i)cprint(j), cprint('\n');
        }
    }
    template<class T>ostream &operator,(ostream &os, T v){
        shyutsuryoku::cprint(v);//cprint(' ');
        return os;
    }
    template<class T>istream &operator,(istream &is, T &v){
        shyutsuryoku::cscan(v);
        return is;
    }
#endif

void misaka_mikoto_is_the_best_girl_ever();

i32 main(){
    #ifdef tavan_sersyv
        freopen(".in","r",stdin);
        freopen(".out","w",stdout);
    #endif
        srand(time(0));
        misaka_mikoto_is_the_best_girl_ever();
    #ifdef tavan_sersyv
        aut '\n', (lf)clock()/CLOCKS_PER_SEC, " 秒\n";
    #endif
    fusrodah 0;
}
ar<i32> g[(i32)5e5+1];
i32 ln[(i32)1e6+1], rg[(i32)1e6+1];
bitset<(i32)5e5+1> us;
void _1(i32 v){
    us[v]=1;
    for(i32 i:g[v])if(!us[i])_1(i);
}
void misaka_mikoto_is_the_best_girl_ever(){
    i32 n, ed=0;
    ain n;
    for(i32 i=1;i<=n;i++){
        i32 l, r;
        ain l, r;
        ln[l]=r;
        rg[r]=i;
    }
    ordered_set lel;
    for(i32 i=1;i<=n+n;i++){
        if(ln[i]){
            ed+=lel.order_of_key(ln[i]);
            lel.in(ln[i]);
        }else{
            lel.erase(i);
        }
    }
    if(ed!=n-1){
        aut "NO";
        return;
    }
    set<i32> lol;
    for(i32 i=1;i<=n+n;i++){
        if(ln[i]){
            for(i32 j:lol){
                if(j>=ln[i])break;
                g[rg[j]].pb(rg[ln[i]]);
                g[rg[ln[i]]].pb(rg[j]);
            }
            lol.in(ln[i]);
        }else{
            lol.erase(i);
        }
    }
    _1(1);
    for(i32 i=1;i<=n;i++){
        if(!us[i]){
            aut "NO";
            return;
        }
    }
    aut "YES";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#ifndef orewabaka
    #define f first
    #define s second
    #define minna(a) a.begin(), a.end()
    #define ovse(a) a.rbegin(), a.rend()
    #define pb push_back
    #define endl aut '\n'
    #define ar vector
    #define var auto
    #define rand() (((rand()<<15)+rand())&INT32_MAX)
    #define ain cin,
    #define aut cout,
    #define $(a) (i64)a.size()
    #define in insert
    #define fusrodah return
    #define mp make_pair
    #define rep(i, n) for(i64 i=0;i<(n);i++)
    #define rep1(i, n) for(i64 i=1;i<(n);i++)
    #define fro2(i, a, b) for(i64 i=(a);i<(b);i++)
    #define elif else if

    typedef int i32;
    typedef unsigned u32;
    typedef long long i64;
    typedef unsigned long long u64;
    typedef pair<i32, i32> p32;
    typedef pair<i64, i64> p64;
    typedef double lf;
    typedef long double ld;
    typedef tree<i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

    namespace shyutsuryoku{
        const i32 STRSZ=3e6+13;
        char inbufer[STRSZ];
        inline void cscan(string& i){
            i32 c=getc(stdin), cnt=0;while(c<=32)c=getc(stdin);
            while(c>32)*(inbufer+cnt)=c,c=getc(stdin),++cnt;
            *(cnt+inbufer)=0;i=inbufer;
        }
        inline void cprint(string& i){
            char *s=new char[i.size()+1];
            strcpy(s, i.c_str());
            while(*s)putchar(*s), s++;
        }
        inline void cprint(const char*& i){
            i32 cnt=0;
            while(*(i+cnt))putc(*(i+cnt), stdout),cnt++;
        }
        inline void cscan(i32&i){
            i=0;i32 c=getc(stdin), b=0;while(c<=32)c=getc(stdin);if(c=='-')b=1, c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
            if(b)i=-i;
        }
        inline void cprint(i32 i){
            if(i<0)putc('-',stdout),i=-i;
            i32 sz=0;char ans[13];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(i64&i){
            i=0;i32 c=getc(stdin), b=1;while(c<=32)c=getc(stdin);if(c=='-')b=-1,c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
            i*=b;
        }
        inline void cprint(i64 i){
            if(i<0)putc('-',stdout),i=-i;
            i32 sz=0;char ans[21];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(u32&i){
            i=0;i32 c=getc(stdin);while(c<=32)c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
        }
        inline void cprint(u32 i){
            i32 sz=0;char ans[12];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(u64&i){
            i=0;i32 c=getc(stdin);while(c<=32)c=getc(stdin);
            while(c>='0'&&c<='9')i*=10,i+=c-'0',c=getc(stdin);
        }
        inline void cprint(u64 i){
            i32 sz=0;char ans[21];while(i||!sz)ans[sz++]=i%10+'0',i/=10;
            while(sz--)putc(ans[sz],stdout);
        }
        inline void cscan(lf&i){
            scanf("%lf", &i);
        }
        inline void cprint(lf i){
            printf("%.20lf", i);
        }
        inline void cprint(char i){
            putc(i, stdout);
        }
        inline void cscan(char&i){
            i32 b=getc(stdin);
            while(b<=32)b=getc(stdin);
            i=b;
        }
        template<class T, class K>inline void cscan(pair<T, K>& i){
            cscan(i.f);cscan(i.s);
        }
        template<class T, class K>inline void cprint(pair<T, K>& i){
            cprint(i.f);cprint(' ');cprint(i.s);cprint('\n');
        }
        template<class T>inline void cscan(ar<T>& i){
            for(var& j:i)cscan(j);
        }
        template<class T>inline void cprint(ar<T>& i){
            for(var& j:i)cprint(j), cprint(' ');
        }
        template<class T>inline void cprint(ar<ar<T> >& i){
            for(var& j:i)cprint(j), cprint('\n');
        }
    }
    template<class T>ostream &operator,(ostream &os, T v){
        shyutsuryoku::cprint(v);//cprint(' ');
        return os;
    }
    template<class T>istream &operator,(istream &is, T &v){
        shyutsuryoku::cscan(v);
        return is;
    }
#endif

void misaka_mikoto_is_the_best_girl_ever();

i32 main(){
    #ifdef tavan_sersyv
        freopen(".in","r",stdin);
        freopen(".out","w",stdout);
    #endif
        srand(time(0));
        misaka_mikoto_is_the_best_girl_ever();
    #ifdef tavan_sersyv
        aut '\n', (lf)clock()/CLOCKS_PER_SEC, " 秒\n";
    #endif
    fusrodah 0;
}
ar<i32> g[(i32)1e6+1];
i32 us[(i32)1e6+1];
void _1(i32 v){
    us[v]=1;
    for(i32 i:g[v])if(!us[i])_1(i);
}
void misaka_mikoto_is_the_best_girl_ever(){
    i32 n, ed=0;
    ain n;
    ar<i32> ln(2*n+1);
    ar<i32> rg(2*n+1);
    for(i32 i=1;i<=n;i++){
        i32 l, r;
        ain l, r;
        ln[l]=r;
        rg[r]=i;
    }
    ordered_set lel;
    for(i32 i=1;i<=n+n;i++){
        if(ln[i]){
            ed+=lel.order_of_key(ln[i]);
            lel.in(ln[i]);
        }else{
            lel.erase(i);
        }
    }
    if(ed!=n-1){
        aut "NO";
        return;
    }
    for(i32 i=1;i<=n+n;i++){
        if(ln[i]){
            for(i32 j:lel){
                if(j>=ln[i])break;
                g[rg[j]].pb(rg[ln[i]]);
                g[rg[ln[i]]].pb(rg[j]);
            }
            lel.in(ln[i]);
        }else{
            lel.erase(i);
        }
    }
    _1(1);
    for(i32 i=1;i<=n;i++){
        if(!us[i]){
            aut "NO";
            return;
        }
    }
    aut "YES";
}


#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pll;
const int N = 1e6 + 5;
int n;
bool vis[N];
map<int, int>mpx, mpy;
vector<pair<int, int>>edges;
vector<int>ans, xy[N], yx[N], seg1[4 * N], seg2[4 * N], adj[N];
void bld(int p, int s, int e)
{
    if(s == e)
    {
        seg1[p] = xy[s];
        seg2[p] = yx[s];
        return;
    }
    int m = (s + e) >> 1, a = p << 1, b = a | 1;
    bld(a, s, m);
    bld(b, m + 1, e);
    merge(seg1[a].begin(), seg1[a].end(), seg1[b].begin(), seg1[b].end(), back_inserter(seg1[p]));
    merge(seg2[a].begin(), seg2[a].end(), seg2[b].begin(), seg2[b].end(), back_inserter(seg2[p]));
}
void qry(int p, int s, int e, int l, int r, int v1, int v2, int id)
{
    if(s > r || e < l)
        return;
    if(s >= l && e <= r)
    {
        vector<int>&tmp1 = seg1[p];
        vector<int>&tmp2 = seg2[p];
        for(int i = tmp1.size() - 1;i >= 0 && tmp1[i] > v1;--i) edges.emplace_back(id, mpx[tmp1[i]]);
        for(int i = 0;i < tmp2.size() && tmp2[i] < v2;++i)      edges.emplace_back(id, mpy[tmp2[i]]);
        return;
    }
    int m = (s + e) >> 1, a = p << 1, b = a | 1;
    qry(a, s, m, l, r, v1, v2, id);
    qry(b, m + 1, e, l, r, v1, v2, id);
}
void dfs(int u)
{
    vis[u] = 1;
    for(auto c : adj[u])
        if(!vis[c])
            dfs(c);
}
void kill()
{
    cout << "NO";
    exit(0);
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 1;i <= n;++i)
    {
        int x, y;
        cin >> x >> y;
        mpy[x] = i;
        mpx[y] = i;
        xy[x].push_back(y);
        yx[y].push_back(x);
    }
    for(int i = 1;i < N;++i)
    {
        sort(xy[i].begin(), xy[i].end());
        sort(yx[i].begin(), yx[i].end());
    }
    bld(1, 0, N - 1);
    for(int i = 1;i < N;++i)
    {
        for(auto &it : xy[i])
        {
            int l = i, r = it;
            ans.clear();
            if(l + 1 <= r - 1)  qry(1, 0, N - 1, l + 1, r - 1, r, l, mpy[l]);
            if(edges.size() > 2 * n - 2)    kill();
        }
    }
    if(edges.size() != 2 * n - 2)   kill();
    for(auto &it : edges)   adj[it.F].push_back(it.S);
    dfs(1);
    for(int i = 1;i <= n;++i)
        if(!vis[i])
            kill();
    cout << "YES";
    return 0;
}


#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pll;
const int N = 1e6 + 5;
int n;
bool vis[N];
map<int, int>mpx, mpy;
vector<pair<int, int>>edges;
vector<int>xy[N], seg1[4 * N], adj[N];
void kill()
{
    cout << "NO";
    exit(0);
}
void bld(int p, int s, int e)
{
    if(s == e)
    {
        seg1[p] = xy[s];
        return;
    }
    int m = (s + e) >> 1, a = p << 1, b = a | 1;
    bld(a, s, m);
    bld(b, m + 1, e);
    merge(seg1[a].begin(), seg1[a].end(), seg1[b].begin(), seg1[b].end(), back_inserter(seg1[p]));
}
void qry(int p, int s, int e, int l, int r, int v1, int id)
{
    if(s > r || e < l)
        return;
    if(s >= l && e <= r)
    {
        vector<int>&tmp1 = seg1[p];
        for(int i = tmp1.size() - 1;i >= 0 && tmp1[i] > v1;--i)
            edges.emplace_back(id, mpx[tmp1[i]]);
        if(edges.size() > n - 1)    kill();
        return;
    }
    int m = (s + e) >> 1, a = p << 1, b = a | 1;
    qry(a, s, m, l, r, v1, id);
    qry(b, m + 1, e, l, r, v1, id);
}
void dfs(int u)
{
    vis[u] = 1;
    for(auto c : adj[u])
        if(!vis[c])
            dfs(c);
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 1;i <= n;++i)
    {
        int x, y;
        cin >> x >> y;
        mpy[x] = i;
        mpx[y] = i;
        xy[x].push_back(y);
    }
    for(int i = 1;i < N;++i)
        sort(xy[i].begin(), xy[i].end());
    bld(1, 0, N - 1);
    for(int i = 1;i < N;++i)
    {
        for(auto &it : xy[i])
        {
            int l = i, r = it;
            if(l + 1 <= r - 1)  qry(1, 0, N - 1, l + 1, r - 1, r, mpy[l]);
        }
    }
    if(edges.size() != n - 1)   kill();
    for(auto &it : edges)   adj[it.F].push_back(it.S), adj[it.S].push_back(it.F);
    dfs(1);
    for(int i = 1;i <= n;++i)
        if(!vis[i])
            kill();
    cout << "YES";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, edges;
vector<int>xy[N], yx[N], seg1[4 * N], seg2[4 * N];
void bld(int p, int s, int e)
{
    if(s == e)
    {
        seg1[p] = xy[s];
        seg2[p] = yx[s];
        return;
    }
    int m = (s + e) >> 1, a = p << 1, b = a | 1;
    bld(a, s, m);
    bld(b, m + 1, e);
    merge(seg1[a].begin(), seg1[a].end(), seg1[b].begin(), seg1[b].end(), back_inserter(seg1[p]));
    merge(seg2[a].begin(), seg2[a].end(), seg2[b].begin(), seg2[b].end(), back_inserter(seg2[p]));
}
int qry(int p, int s, int e, int l, int r, int v1, int v2)
{
    if(s > r || e < l)
        return 0;
    if(s >= l && e <= r)
    {
        vector<int>&tmp1 = seg1[p];
        vector<int>&tmp2 = seg2[p];
        return tmp1.size() - (upper_bound(tmp1.begin(), tmp1.end(), v1) - tmp1.begin())
            + (lower_bound(tmp2.begin(), tmp2.end(), v2) - tmp2.begin());
    }
    int m = (s + e) >> 1, a = p << 1, b = a | 1;
    return qry(a, s, m, l, r, v1, v2) + qry(b, m + 1, e, l, r, v1, v2);
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    if(n == 1)  return cout << "YES", 0;
    for(int i = 0;i < n;++i)
    {
        int x, y;
        cin >> x >> y;
        xy[x].push_back(y);
        yx[y].push_back(x);
    }
    for(int i = 1;i < N;++i)
    {
        sort(xy[i].begin(), xy[i].end());
        sort(yx[i].begin(), yx[i].end());
    }
    bld(1, 0, N - 1);
    for(int i = 1;i < N;++i)
    {
        for(auto &it : xy[i])
        {
            int l = i, r = it, edges_num = 0;
            if(l + 1 <= r - 1)  edges_num = qry(1, 0, N - 1, l + 1, r - 1, r, l);
            if(!edges_num)  return cout << "NO", 0;
            edges += edges_num;
        }
    }
    cout << (edges == 2 * n - 2 ? "YES" : "NO");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, edges;
vector<int>xy[N], yx[N];
vector<int>seg1[4 * N], seg2[4 * N];
void bld(int p, int s, int e)
{
    if(s == e)
    {
        seg1[p] = xy[s];
        seg2[p] = yx[s];
        return;
    }
    int m = (s + e) >> 1, a = p << 1, b = a | 1;
    bld(a, s, m);
    bld(b, m + 1, e);
    merge(seg1[a].begin(), seg1[a].end(), seg1[b].begin(), seg1[b].end(), back_inserter(seg1[p]));
    merge(seg2[a].begin(), seg2[a].end(), seg2[b].begin(), seg2[b].end(), back_inserter(seg2[p]));
}
int qry(int p, int s, int e, int l, int r, int v1, int v2)
{
    if(s > r || e < l)
        return 0;
    if(s >= l && e <= r)
    {
        vector<int>&tmp1 = seg1[p];
        vector<int>&tmp2 = seg2[p];
        return tmp1.size() - (upper_bound(tmp1.begin(), tmp1.end(), v1) - tmp1.begin())
            + (lower_bound(tmp2.begin(), tmp2.end(), v2) - tmp2.begin());
    }
    int m = (s + e) >> 1, a = p << 1, b = a | 1;
    return qry(a, s, m, l, r, v1, v2) + qry(b, m + 1, e, l, r, v1, v2);
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    if(n == 1)  return cout << "YES", 0;
    for(int i = 0;i < n;++i)
    {
        int x, y;
        cin >> x >> y;
        xy[x].push_back(y);
        yx[y].push_back(x);
    }
    for(int i = 1;i < N;++i)
    {
        sort(xy[i].begin(), xy[i].end());
        sort(yx[i].begin(), yx[i].end());
    }
    bld(1, 0, N - 1);
    for(int i = 1;i < N;++i)
    {
        for(auto &it : xy[i])
        {
            int l = i, r = it, edges_num = 0;
            if(l + 1 <= r - 1)  edges_num = qry(1, 0, N - 1, l + 1, r - 1, r, l);
            if(!edges_num)  return cout << "NO", 0;
            edges += edges_num;
        }
    }
    cout << (edges == 2 * n - 2 ? "YES" : "NO");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, edges;
vector<int>xy[N], yx[N];
vector<int>seg1[4 * N], seg2[4 * N];
void bld(int p, int s, int e)
{
    if(s == e)
    {
        seg1[p] = xy[s];
        seg2[p] = yx[s];
        return;
    }
    int m = (s + e) >> 1, a = p << 1, b = a | 1;
    bld(a, s, m);
    bld(b, m + 1, e);
    merge(seg1[a].begin(), seg1[a].end(), seg1[b].begin(), seg1[b].end(), back_inserter(seg1[p]));
    merge(seg2[a].begin(), seg2[a].end(), seg2[b].begin(), seg2[b].end(), back_inserter(seg2[p]));
}
int qry(int p, int s, int e, int l, int r, int v1, int v2)
{
    if(s > r || e < l)
        return 0;
    if(s >= l && e <= r)
    {
        vector<int>&tmp1 = seg1[p];
        vector<int>&tmp2 = seg2[p];
        return tmp1.size() - (upper_bound(tmp1.begin(), tmp1.end(), v1) - tmp1.begin())
            + (lower_bound(tmp2.begin(), tmp2.end(), v2) - tmp2.begin());
    }
    int m = (s + e) >> 1, a = p << 1, b = a | 1;
    return qry(a, s, m, l, r, v1, v2) + qry(b, m + 1, e, l, r, v1, v2);
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 0;i < n;++i)
    {
        int x, y;
        cin >> x >> y;
        xy[x].push_back(y);
        yx[y].push_back(x);
    }
    for(int i = 1;i < N;++i)
    {
        sort(xy[i].begin(), xy[i].end());
        sort(yx[i].begin(), yx[i].end());
    }
    bld(1, 0, N - 1);
    for(int i = 1;i < N;++i)
    {
        for(auto &it : xy[i])
        {
            int l = i, r = it, edges_num = 0;
            if(l + 1 <= r - 1)  edges_num = qry(1, 0, N - 1, l + 1, r - 1, r, l);
            if(!edges_num)  return cout << "NO", 0;
            edges += edges_num;
        }
    }
    cout << (edges == 2 * n - 2 ? "YES" : "NO");
    return 0;
}


#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pll;
const int N = 1e6 + 5;
int n;
bool vis[N];
map<int, int>mpx, mpy;
vector<pair<int, int>>edges;
vector<int>ans, xy[N], yx[N], seg1[4 * N], seg2[4 * N], adj[N];
void bld(int p, int s, int e)
{
    if(s == e)
    {
        seg1[p] = xy[s];
        seg2[p] = yx[s];
        return;
    }
    int m = (s + e) >> 1, a = p << 1, b = a | 1;
    bld(a, s, m);
    bld(b, m + 1, e);
    merge(seg1[a].begin(), seg1[a].end(), seg1[b].begin(), seg1[b].end(), back_inserter(seg1[p]));
    merge(seg2[a].begin(), seg2[a].end(), seg2[b].begin(), seg2[b].end(), back_inserter(seg2[p]));
}
void kill()
{
    cout << "NO";
    exit(0);
}
void qry(int p, int s, int e, int l, int r, int v1, int v2, int id)
{
    if(s > r || e < l)
        return;
    if(s >= l && e <= r)
    {
        vector<int>&tmp1 = seg1[p];
        vector<int>&tmp2 = seg2[p];
        for(int i = tmp1.size() - 1;i >= 0 && tmp1[i] > v1;--i) edges.emplace_back(id, mpx[tmp1[i]]);
        for(int i = 0;i < tmp2.size() && tmp2[i] < v2;++i)      edges.emplace_back(id, mpy[tmp2[i]]);
        if(edges.size() > 2 * n - 2)    kill();
        return;
    }
    int m = (s + e) >> 1, a = p << 1, b = a | 1;
    qry(a, s, m, l, r, v1, v2, id);
    qry(b, m + 1, e, l, r, v1, v2, id);
}
void dfs(int u)
{
    vis[u] = 1;
    for(auto c : adj[u])
        if(!vis[c])
            dfs(c);
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 1;i <= n;++i)
    {
        int x, y;
        cin >> x >> y;
        mpy[x] = i;
        mpx[y] = i;
        xy[x].push_back(y);
        yx[y].push_back(x);
    }
    for(int i = 1;i < N;++i)
    {
        sort(xy[i].begin(), xy[i].end());
        sort(yx[i].begin(), yx[i].end());
    }
    bld(1, 0, N - 1);
    for(int i = 1;i < N;++i)
    {
        for(auto &it : xy[i])
        {
            int l = i, r = it;
            ans.clear();
            if(l + 1 <= r - 1)  qry(1, 0, N - 1, l + 1, r - 1, r, l, mpy[l]);
        }
    }
    if(edges.size() != 2 * n - 2)   kill();
    for(auto &it : edges)   adj[it.F].push_back(it.S);
    dfs(1);
    for(int i = 1;i <= n;++i)
        if(!vis[i])
            kill();
    cout << "YES";
    return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

lli n;
typedef struct UnionFind{
    vector<lli> par; //par[i]:iの親番号 par[3] = 2 : 3の親が2
    vector<lli> size;//size[i]:iの大きさ 自分のみのときは1,根っこにsizeを持たせる*/

    UnionFind(int N=5*1e5+10){/*最初はすべてが根であると初期化*/
        REP(i,0,N){
            par.push_back(i);
            size.push_back(1);
        }
    }

    lli root(lli x){/*データxが属する木の根を再起で得る root(x) = {xの木の根}}*/
        if(par[x] == x)return x;
        return par[x] = root(par[x]);
    }

    void unite(lli x,lli y){/*xとyの併合*/
        lli rx = root(x);
        lli ry = root(y);
        if(rx == ry)return;
        par[rx] = ry; /*xとyの根が同じじゃない: xの根をrxをyの根ryに変更する */
        lli resize = size[rx] + size[ry];
        size[rx] = resize;
        size[ry] = resize;
    }

    bool same(lli x,lli y){
        lli rx = root(x);
        lli ry = root(y);
        return rx == ry;
    }

    lli getSize(lli x){
        lli rx = root(x);
        return size[rx];
    }
};

UnionFind uf;
vector<pair<lli,lli>> v;
bool vis[500010];
bool ng;

void func(lli now){
	if(ng)return;
	if(vis[now])return;

	vis[now]=true;

	REP(i,now+1,n){
		if(v[now].second<v[i].first)break;
		if(v[i].second<v[now].second)continue;

		LOG4(v[now].first,v[now].second,v[i].first,v[i].second);
		if(uf.same(now,i)){
			cout<<"NO"<<endl;
			ng=true;
			return;
		}
		uf.unite(i,now);
		func(i);
	}
}

void solve(){

	scanf("%d",&n);

	v.resize(n);

	REP(i,0,n){
		lli a,b;
		scanf("%d %d",&a,&b);
		v[i]={a,b};
	}
	SORT(v);

	REP(i,0,n){
		func(i);
	}

	if(!ng){
		set<lli> roots;
		REP(i,0,n)roots.insert(uf.root(i));
		if(roots.size()==1)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return;
}

int main(){

	lli t;
	//cin>>t;
	t=1;
	while(t--)solve();

	return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

lli n;
typedef struct UnionFind{
    vector<lli> par; //par[i]:iの親番号 par[3] = 2 : 3の親が2
    vector<lli> size;//size[i]:iの大きさ 自分のみのときは1,根っこにsizeを持たせる*/

    UnionFind(int N=5*1e5+10){/*最初はすべてが根であると初期化*/
        REP(i,0,N){
            par.push_back(i);
            size.push_back(1);
        }
    }

    lli root(lli x){/*データxが属する木の根を再起で得る root(x) = {xの木の根}}*/
        if(par[x] == x)return x;
        return par[x] = root(par[x]);
    }

    void unite(lli x,lli y){/*xとyの併合*/
        lli rx = root(x);
        lli ry = root(y);
        if(rx == ry)return;
        par[rx] = ry; /*xとyの根が同じじゃない: xの根をrxをyの根ryに変更する */
        lli resize = size[rx] + size[ry];
        size[rx] = resize;
        size[ry] = resize;
    }

    bool same(lli x,lli y){
        lli rx = root(x);
        lli ry = root(y);
        return rx == ry;
    }

    lli getSize(lli x){
        lli rx = root(x);
        return size[rx];
    }
};

UnionFind uf;
vector<pair<lli,lli>> v;
bool vis[500010];
bool ng;

void func(lli now){
	if(ng)return;
	if(vis[now])return;

	vis[now]=true;

	REP(i,now+1,n){
		if(v[now].second<v[i].first)break;
		if(v[i].second<v[now].second)continue;

		LOG4(v[now].first,v[now].second,v[i].first,v[i].second);
		if(uf.same(now,i)){
			if(!ng)cout<<"NO"<<endl;
			ng=true;
			return;
		}
		uf.unite(i,now);
		func(i);
		if(ng)break;
	}
}

void solve(){

	cin>>n;

	v.resize(n);

	REP(i,0,n){
		lli a,b;
		//scanf("%d %d",&a,&b);
		cin>>a>>b;
		v[i]={a,b};
	}
	SORT(v);

	REP(i,0,n){
		func(i);
	}

	if(!ng){
		set<lli> roots;
		REP(i,0,n)roots.insert(uf.root(i));
		if(roots.size()==1)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return;
}

int main(){
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	lli t;
	//cin>>t;
	t=1;
	while(t--)solve();

	return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

lli n;
typedef struct UnionFind{
    vector<lli> par; //par[i]:iの親番号 par[3] = 2 : 3の親が2
    vector<lli> size;//size[i]:iの大きさ 自分のみのときは1,根っこにsizeを持たせる*/

    UnionFind(int N=5*1e5+10){/*最初はすべてが根であると初期化*/
        REP(i,0,N){
            par.push_back(i);
            size.push_back(1);
        }
    }

    lli root(lli x){/*データxが属する木の根を再起で得る root(x) = {xの木の根}}*/
        if(par[x] == x)return x;
        return par[x] = root(par[x]);
    }

    void unite(lli x,lli y){/*xとyの併合*/
        lli rx = root(x);
        lli ry = root(y);
        if(rx == ry)return;
        par[rx] = ry; /*xとyの根が同じじゃない: xの根をrxをyの根ryに変更する */
        lli resize = size[rx] + size[ry];
        size[rx] = resize;
        size[ry] = resize;
    }

    bool same(lli x,lli y){
        lli rx = root(x);
        lli ry = root(y);
        return rx == ry;
    }

    lli getSize(lli x){
        lli rx = root(x);
        return size[rx];
    }
};

UnionFind uf;
lli atob[500010];
lli btoa[500010];
lli atoin[500010];
lli btoin[500010];
lli intoa[500010];
lli intob[500010];

void solve(){

	cin>>n;

	priority_queue<pair<lli,lli>,vector<pair<lli,lli>>,greater<pair<lli,lli>>> q;

	REP(i,0,n){
		lli a,b;
		cin>>a>>b;
		q.push({a,i});
		q.push({b,i});
		atob[a]=b;
		btoa[b]=a;
		atoin[a]=i;
		btoin[b]=i;
		intoa[i]=a;
		intob[i]=b;
	}

	set<lli> s;

	lli cnt = 0;
	REP(i,1,2*n+1){
		LOG2(i,q.size());
		if(cnt>=n){
			cout<<"NO"<<endl;
			return;
		}
		while(q.size() && q.top().first==i){
			pair<lli,lli> top = q.top();
			q.pop();
			LOG2(top.first,top.second);
			if(s.find(intob[top.second])!=s.end()){
				s.erase(intob[top.second]);
				continue;
			}
			lli nowI = top.second;
			for(auto e:s){

				LOG2(top.second,atoin[e]);
				LOG2(intoa[e],intoa[nowI]);
				if(intob[nowI]<e)break;
				uf.unite(nowI,btoin[e]);
				cnt++;
			}
			s.insert(intob[top.second]);
		}
	}

	set<lli> anss;
	REP(i,0,n){
		LOG2(i,uf.root(i));
		anss.insert(uf.root(i));
	}

	if(anss.size()==1)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;

	return;
}

int main(){
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	lli t;
	//cin>>t;
	t=1;
	while(t--)solve();

	return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

lli n;
typedef struct UnionFind{
    vector<lli> par; //par[i]:iの親番号 par[3] = 2 : 3の親が2
    vector<lli> size;//size[i]:iの大きさ 自分のみのときは1,根っこにsizeを持たせる*/

    UnionFind(int N=5*1e5+10){/*最初はすべてが根であると初期化*/
        REP(i,0,N){
            par.push_back(i);
            size.push_back(1);
        }
    }

    lli root(lli x){/*データxが属する木の根を再起で得る root(x) = {xの木の根}}*/
        if(par[x] == x)return x;
        return par[x] = root(par[x]);
    }

    void unite(lli x,lli y){/*xとyの併合*/
        lli rx = root(x);
        lli ry = root(y);
        if(rx == ry)return;
        par[rx] = ry; /*xとyの根が同じじゃない: xの根をrxをyの根ryに変更する */
        lli resize = size[rx] + size[ry];
        size[rx] = resize;
        size[ry] = resize;
    }

    bool same(lli x,lli y){
        lli rx = root(x);
        lli ry = root(y);
        return rx == ry;
    }

    lli getSize(lli x){
        lli rx = root(x);
        return size[rx];
    }
};

UnionFind uf;
vector<pair<lli,lli>> v;
bool vis[500010];
bool ng;

void func(lli now){
	if(ng)return;
	if(vis[now])return;

	vis[now]=true;

	REP(i,now+1,n){
		if(v[now].second<v[i].first)break;
		if(v[i].second<v[now].second)continue;

		LOG4(v[now].first,v[now].second,v[i].first,v[i].second);
		if(uf.same(now,i)){
			cout<<"NO"<<endl;
			ng=true;
			return;
		}
		uf.unite(i,now);
		func(i);
	}
}

void solve(){

	cin>>n;

	v.resize(n);

	REP(i,0,n){
		lli a,b;
		scanf("%d %d",&a,&b);
		v[i]={a,b};
	}
	SORT(v);

	REP(i,0,n){
		func(i);
	}

	if(!ng){
		set<lli> roots;
		REP(i,0,n)roots.insert(uf.root(i));
		if(roots.size()==1)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return;
}

int main(){

	lli t;
	//cin>>t;
	t=1;
	while(t--)solve();

	return 0;
}