    #include <bits/stdc++.h>
    using namespace std;
     
    using pii = pair<int, int>;
    template <class T>
    using V = vector<T>;
    template <class T>
    using VV = V<V<T>>;
     
    #define rep(i, n) rep2(i, 0, n)
    #define rep2(i, m, n) for (int i = m; i < (n); i++)
     
    void ng() {
        puts("No");
        exit(0);
    }
     
    int main() {
        int N;
        cin >> N;
        V<int> A(N), B(N);
        int sz = N * 2;
        V<int> tp(sz), com(sz, -1);
     
        rep(i, N) {
            cin >> A[i] >> B[i];
            if (A[i] != -1) {
                --A[i];
                if (tp[A[i]]) ng();
                tp[A[i]] = i + 1;
            }
            if (B[i] != -1) {
                --B[i];
                if (tp[B[i]]) ng();
                tp[B[i]] = -(i + 1);
            }
     
            if (A[i] != -1 && B[i] != -1) {
                if (A[i] > B[i]) ng();
                com[A[i]] = B[i];
                com[B[i]] = A[i];
            }
        }
     
        V<bool> dp(sz + 1);
        dp[0] = true;
     
        rep(i, sz) {
            if (!dp[i]) continue;
            for (int j = i + 1; j < sz; j += 2) {
                int w = (j - i + 1) / 2;
                bool ok = true;
     
                rep(k, w) {
                    int p = i + k, q = i + k + w;
                    if (com[p] != -1 && com[p] != q) {
                        ok = false;
                    }
                    if (com[q] != -1 && com[q] != p) {
                        ok = false;
                    }
     
                    if (tp[p] != 0 && tp[q] != 0 && tp[p] + tp[q] != 0) {
                        ok = false;
                    }
                    if (tp[p] < 0 || tp[q] > 0) {
                        ok = false;
                    }
                }
                if (ok) {
                    dp[j + 1] = true;
                }
            }
        }
        puts(dp[sz] ? "Yes" : "No");
     
        return 0;
    }
#include<bits/stdc++.h>
using namespace std;
#define int ll
#define ALL(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}
template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}

signed main(){
    int N,M;cin>>N>>M;

    map<int,vector<int>> v;
    rep(i,M){
        int h,w;cin>>h>>w;
        v[h].push_back(w);
    }

    set<int> st;
    st.insert(N);

    for(auto &p:v){
        vector<int> nxt,ers;
        for(auto &j:p.second){
            if(st.count(j)){
                if(!st.count(j-1) and !st.count(j+1)) ers.push_back(j);
            }else{
                if(st.count(j-1) or st.count(j+1)) nxt.push_back(j);
            }
        }
        for(auto &j:ers) st.erase(j);
        for(auto &j:nxt) st.insert(j);
    }
    cout<<st.size()<<endl;
    return 0;
}