#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
#define MPlus(x,y) {x=(x+y)%M;}
#define MSub(x,y) {x=(x-y+M)%M;}
#define MMul(x,y) {x=(x*y)%M;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int q;
  cin>>q;
  while(q--){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    int l=0,r=n-1;
    vector<P> res;
    while(r>l){
      while(l<r&&(l%2==0&&s[l]=='(')||(l%2&&s[l]==')')) l++;
      while(l<r&&(r%2==0&&s[r]=='(')||(r%2&&s[r]==')')) r--;
      if(l==r&&(l%2==0&&s[l]=='(')||(l%2&&s[l]==')')) break;
      if(l>r) break;
      res.PB(P(l+1,r+1));
      FOR(i,l,r+1){
        if(i!=l&&i!=r) continue;
        if(s[i]=='(') s[i]=')';
        else s[i]='(';
      }
    }

    rep(i,n){
      if(i%2==0&&s[i]==')'){
        s[i]='(';
        res.PB(P(i+1,i+1));
      }else if(i%2&&s[i]=='('){
        s[i]=')';
        res.PB(P(i+1,i+1));
      }
    }

    //cout<<res.size()<<endl;
    //cout<<s<<endl;
    int kk=n/2;
    for(int i=1;i<=n;i+=2){
      if(kk>k){
        if(s[i]=='(') s[i]=')';
        else s[i]='(';
        if(s[i+1]=='(') s[i+1]=')';
        else s[i+1]='(';
        res.PB(P(i+1,i+2));
        kk--;
      }
    }

    //cout<<s<<endl;

    cout<<res.size()<<endl;
    for(P p:res){
      cout<<p.F<<' '<<p.S<<endl;
    }

  }

}


#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
#define MPlus(x,y) {x=(x+y)%M;}
#define MSub(x,y) {x=(x-y+M)%M;}
#define MMul(x,y) {x=(x*y)%M;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int q;
  cin>>q;
  while(q--){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    int l=0,r=n-1;
    vector<P> res;
    while(r>l){
      while(l<r&&(l%2==0&&s[l]=='(')||(l%2&&s[l]==')')) l++;
      while(l<r&&(r%2==0&&s[r]=='(')||(r%2&&s[r]==')')) r--;
      if(l>r) break;
      res.PB(P(l+1,r+1));
      FOR(i,l,r+1){
        if(s[i]=='(') s[i]=')';
        else s[i]='(';
      }
    }
    //cout<<res.size()<<endl;
    //cout<<s<<endl;
    int kk=n/2;
    for(int i=1;i<=n;i+=2){
      if(kk>k){
        if(s[i]=='(') s[i]=')';
        else s[i]='(';
        if(s[i+1]=='(') s[i+1]=')';
        else s[i+1]='(';
        res.PB(P(i+1,i+2));
        kk--;
      }
    }

    //cout<<s<<endl;

    cout<<res.size()<<endl;
    for(P p:res){
      cout<<p.F<<' '<<p.S<<endl;
    }

  }

}


#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
#define MPlus(x,y) {x=(x+y)%M;}
#define MSub(x,y) {x=(x-y+M)%M;}
#define MMul(x,y) {x=(x*y)%M;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int q;
  cin>>q;
  while(q--){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    int l=0,r=n-1;
    vector<P> res;
    while(r>l){
      while(l<r&&(l%2==0&&s[l]=='(')||(l%2&&s[l]==')')) l++;
      while(l<r&&(r%2==0&&s[r]=='(')||(r%2&&s[r]==')')) r--;
      if(l==r&&(l%2==0&&s[l]=='(')||(l%2&&s[l]==')')) break;
      if(l>r) break;
      res.PB(P(l+1,r+1));
      FOR(i,l,r+1){
        if(s[i]=='(') s[i]=')';
        else s[i]='(';
      }
    }
    //cout<<res.size()<<endl;
    //cout<<s<<endl;
    int kk=n/2;
    for(int i=1;i<=n;i+=2){
      if(kk>k){
        if(s[i]=='(') s[i]=')';
        else s[i]='(';
        if(s[i+1]=='(') s[i+1]=')';
        else s[i+1]='(';
        res.PB(P(i+1,i+2));
        kk--;
      }
    }

    //cout<<s<<endl;

    cout<<res.size()<<endl;
    for(P p:res){
      cout<<p.F<<' '<<p.S<<endl;
    }

  }

}


#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
#define MPlus(x,y) {x=(x+y)%M;}
#define MSub(x,y) {x=(x-y+M)%M;}
#define MMul(x,y) {x=(x*y)%M;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int q;
  cin>>q;
  while(q--){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    int l=0,r=n-1;
    vector<P> res;
    while(r>l){
      while(l<r&&(l%2==0&&s[l]=='(')||(l%2&&s[l]==')')) l++;
      while(l<r&&(r%2==0&&s[r]=='(')||(r%2&&s[r]==')')) r--;
      if(l>=r) break;
      res.PB(P(l+1,r+1));
      FOR(i,l,r+1){
        if(s[i]=='(') s[i]=')';
        else s[i]='(';
      }
    }
    //cout<<res.size()<<endl;
    //cout<<s<<endl;
    int kk=n/2;
    for(int i=1;i<=n;i+=2){
      if(kk>k){
        if(s[i]=='(') s[i]=')';
        else s[i]='(';
        if(s[i+1]=='(') s[i+1]=')';
        else s[i+1]='(';
        res.PB(P(i+1,i+2));
        kk--;
      }
    }

    //cout<<s<<endl;

    cout<<res.size()<<endl;
    for(P p:res){
      cout<<p.F<<' '<<p.S<<endl;
    }

  }

}


#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
#define MPlus(x,y) {x=(x+y)%M;}
#define MSub(x,y) {x=(x-y+M)%M;}
#define MMul(x,y) {x=(x*y)%M;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int q;
  cin>>q;
  while(q--){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    int l=0,r=n-1;
    vector<P> res;
    while(r>l){
      while(l<r&&(l%2==0&&s[l]=='(')||(l%2&&s[l]==')')) l++;
      while(l<r&&(r%2==0&&s[r]=='(')||(r%2&&s[r]==')')) r--;
      if(l==r&&(l%2==0&&s[l]=='(')||(l%2&&s[l]==')')) break;
      if(l>r) break;
      res.PB(P(l+1,r+1));
      FOR(i,l,r+1){
        if(s[i]=='(') s[i]=')';
        else s[i]='(';
      }
    }

    rep(i,n){
      if(i%2==0&&s[i]==')'){
        s[i]='(';
        res.PB(P(i+1,i+1));
      }else if(i%2&&s[i]=='('){
        s[i]=')';
        res.PB(P(i+1,i+1));
      }
    }

    //cout<<res.size()<<endl;
    //cout<<s<<endl;
    int kk=n/2;
    for(int i=1;i<=n;i+=2){
      if(kk>k){
        if(s[i]=='(') s[i]=')';
        else s[i]='(';
        if(s[i+1]=='(') s[i+1]=')';
        else s[i+1]='(';
        res.PB(P(i+1,i+2));
        kk--;
      }
    }

    //cout<<s<<endl;

    cout<<res.size()<<endl;
    for(P p:res){
      cout<<p.F<<' '<<p.S<<endl;
    }

  }

}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define mem(a, b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define DBG printf("this is a input\n")
int T, n ,k;
vector<pair<int,int>>v;
string str;
string str_ans;
void solve()
{
    for(int i = 0 ; i < str.length() ;)
    {
        if(str[i] == '(' && str[i+1] == ')')
            i += 2;
        else if(str[i] == ')')
        {
            for(int j = i+1 ; j < str.length() ; j ++)
            {
                if(str[j] == '(')
                {
                    reverse(str.begin()+i, str.begin() + j + 1);
                    v.push_back(make_pair(i+1,j+1));
                    i += 2;
                    break;
                }
            }
        }
        else if(str[i] == '(')
        {
            for(int j = i+2 ; j < str.length() ; j ++)
            {
                if(str[j] == '(')
                {
                    reverse(str.begin() + i + 1, str.begin() + j + 2);
                    v.push_back(make_pair(i+2,j+1));
                    i += 2;
                    break;
                }
            }
        }
    }
}
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>T;
    while(T --)
    {
        v.clear();
        cin>>n>>k;
        cin>>str;
        solve();
        if(n/2 != k)
            v.push_back(make_pair((k-1)*2+1,n-2));
        cout<<v.size()<<endl;
        for(int i = 0 ; i < v.size() ; i ++)
            cout<<v[i].first<<" "<<v[i].second<<endl;
    }
}
/*
4
10 3
))()()()((

*/


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define mem(a, b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define DBG printf("this is a input\n")
int T, n ,k;
vector<pair<int,int>>v;
string str;
string str_ans;
void solve()
{
    for(int i = 0 ; i < str.length() ;)
    {
        if(str[i] == '(' && str[i+1] == ')')
            i += 2;
        else if(str[i] == ')')
        {
            for(int j = i+1 ; j < str.length() ; j ++)
            {
                if(str[j] == '(')
                {
                    reverse(str.begin()+i, str.begin() + j + 1);
                    v.push_back(make_pair(i+1,j+1));
                    //cout<<str<<endl;
                    i += 2;
                    break;
                }
            }
        }
        else if(str[i] == '(')
        {
            for(int j = i+2 ; j < str.length() ; j ++)
            {
                if(str[j] == '(')
                {
                    reverse(str.begin() + i + 1, str.begin() + j + 2);
                    v.push_back(make_pair(i+2,j+2));
                    //cout<<str<<endl;
                    i += 2;
                    break;
                }
            }
        }
    }
}
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>T;
    while(T --)
    {
        v.clear();
        cin>>n>>k;
        cin>>str;
        solve();
        //cout<<str<<endl;
        if(n/2 != k)
            v.push_back(make_pair((k-1)*2+2,n-1));
        cout<<v.size()<<endl;
        for(int i = 0 ; i < v.size() ; i ++)
            cout<<v[i].first<<" "<<v[i].second<<endl;
    }
}
/*
4
10 3
))()()()((

*/


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define mem(a, b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define DBG printf("this is a input\n")
int T, n ,k;
vector<pair<int,int>>v;
string str;
string str_ans;
void solve()
{
    for(int i = 0 ; i < str.length() ;)
    {
        if(str[i] == '(' && str[i+1] == ')')
            i += 2;
        else if(str[i] == ')')
        {
            for(int j = i+1 ; j < str.length() ; j ++)
            {
                if(str[j] == '(')
                {
                    reverse(str.begin()+i, str.begin() + j + 1);
                    v.push_back(make_pair(i+1,j+1));
                    //cout<<str<<endl;
                    i += 2;
                    break;
                }
            }
        }
        else if(str[i] == '(')
        {
            for(int j = i+2 ; j < str.length() ; j ++)
            {
                if(str[j] == ')')
                {
                    reverse(str.begin() + i + 1, str.begin() + j + 2);
                    v.push_back(make_pair(i+2,j+1));
                    //cout<<str<<endl;
                    i += 2;
                    break;
                }
            }
        }
    }
}
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>T;
    while(T --)
    {
        v.clear();
        cin>>n>>k;
        cin>>str;
        solve();
        //cout<<str<<endl;
        if(n/2 != k)
            v.push_back(make_pair((k-1)*2+2,n-1));
        cout<<v.size()<<endl;
        for(int i = 0 ; i < v.size() ; i ++)
            cout<<v[i].first<<" "<<v[i].second<<endl;
    }
}
/*
4
10 3
))()()()((

*/


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define mem(a, b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define DBG printf("this is a input\n")
int T, n ,k;
vector<pair<int,int>>v;
string str;
string str_ans;
void solve()
{
    for(int i = 0 ; i < str.length() ;)
    {
        if(str[i] == '(' && str[i+1] == ')')
            i += 2;
        else if(str[i] == ')')
        {
            for(int j = i+1 ; j < str.length() ; j ++)
            {
                if(str[j] == '(')
                {
                    reverse(str.begin()+i, str.begin() + j + 1);
                    v.push_back(make_pair(i+1,j+1));
                    i += 2;
                    break;
                }
            }
        }
        else if(str[i] == '(')
        {
            for(int j = i+2 ; j < str.length() ; j ++)
            {
                if(str[j] == '(')
                {
                    reverse(str.begin() + i + 1, str.begin() + j + 2);
                    v.push_back(make_pair(i+2,j+1));
                    i += 2;
                    break;
                }
            }
        }
    }
}
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>T;
    while(T --)
    {
        v.clear();
        cin>>n>>k;
        cin>>str;
        solve();
        if(n/2 != k)
            v.push_back(make_pair((k-1)*2+2,n-1));
        cout<<v.size()<<endl;
        for(int i = 0 ; i < v.size() ; i ++)
            cout<<v[i].first<<" "<<v[i].second<<endl;
    }
}
/*
4
10 3
))()()()((

*/


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define mem(a, b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define DBG printf("this is a input\n")
int T, n ,k;
vector<pair<int,int>>v;
string str;
string str_ans;
void solve()
{
    for(int i = 0 ; i < str.length() ;)
    {
        //cout<<str<<endl;
        if(str[i] == '(' && str[i+1] == ')')
            i += 2;
        else if(str[i] == ')')
        {
            for(int j = i+1 ; j < str.length() ; j ++)
            {
                if(str[j] == '(')
                {
                    reverse(str.begin()+i, str.begin() + j + 1);
                    v.push_back(make_pair(i+1,j+1));
                    //cout<<str<<endl;
                    i += 2;
                    break;
                }
            }
        }
        else if(str[i] == '(')
        {
            for(int j = i+2 ; j < str.length() ; j ++)
            {
                if(str[j] == ')')
                {
                    //cout<<i<<" "<<j<<endl;
                    reverse(str.begin() + i + 1, str.begin() + j + 1);
                    v.push_back(make_pair(i+2,j+1));
                    //cout<<str<<endl;
                    i += 2;
                    break;
                }
            }
        }
    }
}
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>T;
    while(T --)
    {
        v.clear();
        cin>>n>>k;
        cin>>str;
        solve();
        //cout<<str<<endl;
        if(n/2 != k)
            v.push_back(make_pair((k-1)*2+2,n-1));
        cout<<v.size()<<endl;
        for(int i = 0 ; i < v.size() ; i ++)
            cout<<v[i].first<<" "<<v[i].second<<endl;
    }
}
/*
100
8 1
(()(()))

*/


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define mem(a, b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define DBG printf("this is a input\n")
int T, n ,k;
vector<pair<int,int>>v;
string str;
string str_ans;
void solve()
{
    for(int i = 0 ; i < str.length() ;)
    {
        //cout<<str<<endl;
        if(str[i] == '(' && str[i+1] == ')')
            i += 2;
        else if(str[i] == ')')
        {
            for(int j = i+1 ; j < str.length() ; j ++)
            {
                if(str[j] == '(')
                {
                    reverse(str.begin()+i, str.begin() + j + 1);
                    v.push_back(make_pair(i+1,j+1));
                    //cout<<str<<endl;
                    i += 2;
                    break;
                }
            }
        }
        else if(str[i] == '(')
        {
            for(int j = i+2 ; j < str.length() ; j ++)
            {
                if(str[j] == ')')
                {
                    //cout<<i<<" "<<j<<endl;
                    reverse(str.begin() + i + 1, str.begin() + j + 2);
                    v.push_back(make_pair(i+2,j+1));
                    //cout<<str<<endl;
                    i += 2;
                    break;
                }
            }
        }
    }
}
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>T;
    while(T --)
    {
        v.clear();
        cin>>n>>k;
        cin>>str;
        solve();
        //cout<<str<<endl;
        if(n/2 != k)
            v.push_back(make_pair((k-1)*2+2,n-1));
        cout<<v.size()<<endl;
        for(int i = 0 ; i < v.size() ; i ++)
            cout<<v[i].first<<" "<<v[i].second<<endl;
    }
}
/*
100
8 1
(()(()))

*/


#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>

using namespace std;

int main(void)
{
	string s;
	int t, n, k, x;
	cin >> t;
	for(int i = 0; i < t; i++)
	{
		scanf("%d %d", &n, &k);
		cin >> s;
		vector<int> u, v;
		int size = s.size();
		for(int j = 0; j < size; j++)
		{
			if(s[j] == '(')
				u.push_back(j + 1);
		}
		x = 1;
		int usize = u.size();
		while(k != 1)
		{
			v.push_back(x);
			x += 2;
			k--; usize--;
		}
		for(int i = 0; i < usize; i++)
		{
			v.push_back(x);
			x++;
		}
		int vsize = v.size();
		int sum = 0;
		printf("%d\n", vsize);
		for(int j = 0; j < vsize; j++)
		{
			printf("%d %d\n", v[j], u[j]);
		}
	}
}


#include <iostream>
#include <string.h>
#include <vector>
using namespace std;

int main(void)
{
	int t, n, k, count;
	cin >> t;
	for(int i = 0; i < t; i++)
	{
		count = 0;
		bool f = true;
		scanf("%d %d", &n, &k);
		vector<int> check(n + 5), v(n + 5);
		vector<pair<int,int>> func;
		char str[4000];
		scanf("%s", str);
		int size = strlen(str);
		for(int j = 0; j < size; j++)
		{
			if(str[j] == '(') v[j + 1] = 1;
			else v[j + 1] = 2;
		}
		for(int j = 0; j < (k - 1) * 2; j++)
		{
			if(f) check[j + 1] = 1;
			else check[j + 1] = 2;
			if(f) f = false;
			else f = true;
		}
		int index = (k - 1) * 2 + 1;
		for(int j = 0; j < (n - 2 * (k - 1)) / 2; j++)
			check[index++] = 1;
		for(int j = 0; j < (n - 2 * (k - 1)) / 2; j++)
			check[index++] = 2;
		for(int j = 1; j <= n; j++)
		{
			if(check[j] != v[j])
			{
				for(int p = j + 1; p <= n; p++)
				{
					if(v[p] == check[j])
					{
						func.push_back({ j, p });
						count++;
						for(int r = j; r < (j + p) / 2; r++)
						{
							int temp = v[r];
							v[r] = v[(j + p) - r];
							v[(j + p) - r] = temp;
						}
						break;
					}
				}
			}
		}
		printf("%d\n", count);
		int fsize = func.size();
		for(int j = 0; j < fsize; j++)
			printf("%d %d\n", func[j].first, func[j].second);
	}
}


#include<bits/stdc++.h>
using namespace std;
int t,n,k;
char a[2002];
pair<int,int> c[1002];
main()
{
	cin>>t;
	while(t--)
	{
		cin>>n>>k;
		int x = 0,d = 0;
		for(int i = 1;i <= n;i++)
		{
			cin>>a[i];
			if(a[i] == '(')
			{
				x++;
				if(x == i)continue;
				d++;
				c[d].first = x;
				c[d].second = i;
			}
		}
		cout<<d+k-1<<endl;
		for(int i = 1;i <= d;i++)
			cout<<c[i].first<<" "<<c[i].second<<endl;
		for(int i = 1;i < k;i++)
		{
			cout<<i*2<<" "<<n/2+i<<endl;
		}
	}
}


#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>

using namespace std;

int main(void)
{
	string s;
	int t, n, k, x;
	cin >> t;
	for(int i = 0; i < t; i++)
	{
		scanf("%d %d", &n, &k);
		cin >> s;
		vector<int> u, v;
		int size = s.size();
		for(int j = 0; j < size; j++)
		{
			if(s[j] == '(')
				u.push_back(j + 1);
		}
		x = 1;
		int usize = u.size();
		while(k != 1)
		{
			v.push_back(x);
			x += 2;
			k--; usize--;
		}
		for(int i = 0; i < usize; i++)
		{
			v.push_back(x);
			x++;
		}
		int vsize = v.size();
		int sum = 0;
		for(int j = 0; j < vsize; j++)
			sum += abs(v[j] - u[j]);
		printf("%d\n", sum);
		for(int j = 0; j < vsize; j++)
		{
			for(int p = u[j]; p > v[j]; p--)
				printf("%d %d\n", p - 1, p);
		}
	}
}


#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>

using namespace std;

int main(void)
{
	string s;
	int t, n, k, x;
	cin >> t;
	for(int i = 0; i < t; i++)
	{
		scanf("%d %d", &n, &k);
		cin >> s;
		vector<int> u, v;
		int size = s.size();
		for(int j = 0; j < size; j++)
		{
			if(s[j] == '(')
				u.push_back(j + 1);
		}
		x = 1;
		int usize = u.size();
		while(k != 1)
		{
			v.push_back(x);
			x += 2;
			k--; usize--;
		}
		for(int i = 0; i < usize; i++)
		{
			v.push_back(x);
			x++;
		}
		int vsize = v.size();
		int sum = 0;
		for(int j = 0; j < vsize; j++)
			if(v[j] != u[j]) sum++;
		printf("%d\n", sum);
		for(int j = 0; j < vsize; j++)
		{
			if(v[j] != u[j])
				printf("%d %d\n", v[j], u[j]);
		}
	}
}


#include <iostream>
#include <string.h>
#include <vector>
using namespace std;

int main(void)
{
	int t, n, k, count;
	cin >> t;
	for(int i = 0; i < t; i++)
	{
		count = 0;
		bool f = true;
		scanf("%d %d", &n, &k);
		vector<int> check(n + 5), v(n + 5);
		vector<pair<int,int>> func;
		char str[4000];
		scanf("%s", str);
		int size = strlen(str);
		for(int j = 0; j < size; j++)
		{
			if(str[j] == '(') v[j + 1] = 1;
			else v[j + 1] = 2;
		}
		for(int j = 0; j < (k - 1) * 2; j++)
		{
			if(f) check[j + 1] = 1;
			else check[j + 1] = 2;
			if(f) f = false;
			else f = true;
		}
		int index = (k - 1) * 2 + 1;
		for(int j = 0; j < (n - 2 * (k - 1)) / 2; j++)
			check[index++] = 1;
		for(int j = 0; j < (n - 2 * (k - 1)) / 2; j++)
			check[index++] = 2;
		for(int j = 1; j <= n; j++)
		{
			if(check[j] != v[j])
			{
				for(int p = j + 1; p <= n; p++)
				{
					if(v[p] == check[j])
					{
						func.push_back({ j, p });
						count++;
						for(int r = j; r <= (j + p) / 2; r++)
						{
							int temp = v[r];
							v[r] = v[(j + p) - r];
							v[(j + p) - r] = temp;
						}
						break;
					}
				}
			}
		}
		printf("%d\n", count);
		int fsize = func.size();
		for(int j = 0; j < fsize; j++)
			printf("%d %d\n", func[j].first, func[j].second);
	}
}


#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>

using namespace std;

int main(void)
{
	string s;
	int t, n, k, x;
	cin >> t;
	for(int i = 0; i < t; i++)
	{
		scanf("%d %d", &n, &k);
		cin >> s;
		vector<int> u, v;
		int size = s.size();
		for(int j = 0; j < size; j++)
		{
			if(s[j] == '(')
				u.push_back(j + 1);
		}
		x = 1;
		int usize = u.size();
		while(k != 1)
		{
			v.push_back(x);
			x += 2;
			k--; usize--;
		}
		for(int i = 0; i < usize; i++)
		{
			v.push_back(x);
			x++;
		}
		int vsize = v.size();
		int sum = 0;
		for(int j = 0; j < vsize; j++)
			sum += abs(v[j] - u[j]);
		printf("%d\n", sum);
		for(int j = 0; j < vsize; j++)
		{
			for(int p = u[j]; p > v[j]; p--)
				printf("%d %d\n", p, p - 1);
		}
	}
}


#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>

using namespace std;

int main(void)
{
	string s;
	int t, n, k, x;
	cin >> t;
	for(int i = 0; i < t; i++)
	{
		scanf("%d %d", &n, &k);
		cin >> s;
		vector<int> u, v;
		int size = s.size();
		for(int j = 0; j < size; j++)
		{
			if(s[j] == '(')
				u.push_back(j + 1);
		}
		x = 1;
		int usize = u.size();
		while(k != 1)
		{
			v.push_back(x);
			x += 2;
			k--; usize--;
		}
		for(int i = 0; i < usize; i++)
		{
			v.push_back(x);
			x++;
		}
		int vsize = v.size();
		int sum = 0;
		for(int j = 0; j < vsize; j++)
			if(v[j] != u[j]) sum++;
		printf("%d\n", sum);
		for(int j = 0; j < vsize; j++)
		{
			if(v[j] != u[j])
			{
				if(v[j] < u[j])
					printf("%d %d\n", v[j], u[j]);
				else
					printf("%d %d\n", u[j], v[j]);
			}
		}
	}
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<vector>
#include<cstdio>
#include<set>
using namespace std;
const int maxn=1e5+10;
string s,t;
void reverse_sub(string &s, int l, int r) {
    for(int i=0;i<(r - l + 1) / 2;i++) {
        swap(s[l + i], s[r - i]);
    }
}

int main()
{
    int T,n,k;

    //s="1234567";
    //reverse(0,3);
    //cout<<s;
    cin>>T;
    while(T--){
        scanf("%d%d",&n,&k);
        t="";
        cin>>s;
        k--;
        for(int i=1;i<=k;i++){
            t+="()";
        }
        for(int i=1;i<=(n-k*2)/2;i++){
            t+="(";
        }
        for(int i=1;i<=(n-2*k)/2;i++){
            t+=")";
        }
        for(int i=0;i<n;i++) {
            int p = i;
            while (s[p] != t[i]) {
                p++;
            }
            cout << i + 1 << " " << p + 1 << "\n";
            reverse_sub(s, i, p);
        }
    }
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<vector>
#include<cstdio>
#include<set>
using namespace std;
const int maxn=1e5+10;
string s,t;
void reverse_sub(string &s, int l, int r) {
    for(int i=0;i<(r - l + 1) / 2;i++) {
        swap(s[l + i], s[r - i]);
    }
}

int main()
{
    int T,n,k;

    //s="1234567";
    //reverse(0,3);
    //cout<<s;
    cin>>T;
    while(T--){
        scanf("%d%d",&n,&k);
        t="";
        cin>>s;
        k--;
        for(int i=1;i<=k;i++){
            t+="()";
        }
        for(int i=1;i<=(n-k*2)/2;i++){
            t+="(";
        }
        for(int i=1;i<=(n-2*k)/2;i++){
            t+=")";
        }
        cout<<n<<endl;
        for(int i=0;i<n;i++) {
            int p = i;
            while (s[p] != t[i]) {
                p++;
            }
            cout << i + 1 << " " << p + 1 << "\n";
            reverse_sub(s, i, p);
        }
    }
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<vector>
#include<cstdio>
#include<set>
using namespace std;
const int maxn=1e5+10;
string s,t;
void reverse(int x,int y){
    char tmp;int c=0;
    for(int i=x;i<=(y+x)/2;i++){
        tmp=s[i];
        s[i]=s[y-c];
        s[y-c]=tmp;
        c++;
    }
}
int main()
{
    int T,n,k;

    //s="1234567";
    //reverse(0,3);
    //cout<<s;
    cin>>T;
    while(T--){
        scanf("%d%d",&n,&k);
        t="";
        cin>>s;
        for(int i=1;i<=k;i++){
            t+="()";
        }
        for(int i=1;i<=(n-k*2)/2;i++){
            t+=")";
        }
        for(int i=1;i<=(n-2*k)/2;i++){
            t+="(";
        }
        cout<<n<<endl;
        for(int i=0;i<n;i++){
            int p=i;
            while(s[i]!=t[p]) p++;
            cout<<i+1<<" "<<p+1<<endl;
            reverse(i,p);
        }
    }
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<vector>
#include<cstdio>
#include<set>
using namespace std;
const int maxn=1e5+10;
string s,t;
void reverse(int x,int y){
    char tmp;int c=0;
    for(int i=x;i<=(y+x)/2;i++){
        tmp=s[i];
        s[i]=s[y-c];
        s[y-c]=tmp;
        c++;
    }
}
int main()
{
    int T,n,k;

    //s="1234567";
    //reverse(0,3);
    //cout<<s;
    cin>>T;
    while(T--){
        scanf("%d%d",&n,&k);
        t="";
        cin>>s;
        for(int i=1;i<=k;i++){
            t+="()";
        }
        for(int i=1;i<=(n-k*2)/2;i++){
            t+=")";
        }
        for(int i=1;i<=(n-2*k)/2;i++){
            t+="(";
        }
        cout<<n<<endl;
        for(int i=0;i<n;i++){
            int p=0;
            while(s[i]!=t[p]) p++;
            cout<<i+1<<" "<<p+1<<endl;
            reverse(i,p);
        }
    }
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<vector>
#include<cstdio>
#include<set>
using namespace std;
const int maxn=1e5+10;
string s,t;
void reverse_sub(string &s, int l, int r) {
    for(int i=0;i<(r - l + 1) / 2;i++) {
        swap(s[l + i], s[r - i]);
    }
}

int main()
{
    int T,n,k;

    //s="1234567";
    //reverse(0,3);
    //cout<<s;
    cin>>T;
    while(T--){
        scanf("%d%d",&n,&k);
        t="";
        cin>>s;
        for(int i=1;i<=k;i++){
            t+="()";
        }
        for(int i=1;i<=(n-k*2)/2;i++){
            t+=")";
        }
        for(int i=1;i<=(n-2*k)/2;i++){
            t+="(";
        }
        for(int i=0;i<n;i++) {
            int p = i;
            while (s[p] != t[i]) {
                p++;
            }
            cout << i + 1 << " " << p + 1 << "\n";
            reverse_sub(s, i, p);
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        string str;
        cin>>str;
        vector<pair<int,int>>ans;

        for(int i=0;i<n;)
        {
            if(str[i]=='(' && str[i+1]!=')')
            {
                for(int j=i+1;j<n;j++)
                {
                    if(str[j]==')')
                        {reverse(str.begin()+i+1,str.begin()+j+1);
                         ans.pb({i+1,j});
                         i+=2;
                        // cout<<"here"<<endl;
                         break;
                         }
                }
            }
            else if(str[i]==')')
            {
                for(int j=i+1;j<n;j++)
                {
                    if(str[j]=='(')
                    {
                        reverse(str.begin()+i,str.begin()+j+1);
                        ans.pb({i,j});
                        i+=2;
                        break;
                    }
                }
            }
            else i+=2;
        }
        int p=k-1;
        //cout<<str<<endl;
        reverse(str.begin()+2*p+1,str.begin()+n-1);
        ans.pb({2*p+1,n-1});
        cout<<ans.size()<<endl;
        for(auto u:ans)
        {
            cout<<u.first+1<<" "<<u.second+1<<endl;
        }

    }
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        string str;
        cin>>str;
        vector<pair<int,int>>ans;

        for(int i=0;i<n;)
        {
            if(str[i]=='(' && str[i+1]!=')')
            {
                for(int j=i+1;j<n;j++)
                {
                    if(str[j]==')')
                        {reverse(str.begin()+i+1,str.begin()+j+1);
                         ans.pb({i+1,j});
                         //cout<<i+1<<" "<<j<<endl;
                         i+=2;
                        // cout<<"here"<<endl;
                         break;
                         }
                }
            }
            else if(str[i]==')')
            {
                for(int j=i+1;j<n;j++)
                {
                    if(str[j]=='(')
                    {
                        reverse(str.begin()+i,str.begin()+j+1);
                       // cout<<i<<" "<<j<<endl;
                        ans.pb({i,j});
                        i+=2;
                        break;
                    }
                }
            }
            else i+=2;
        }

        int p=k-1;
        if(p>=0 && k!=n/2){
        //cout<<str<<endl;
        reverse(str.begin()+2*p+1,str.begin()+n-1);
        ans.pb({2*p+1,n-2});
        }
        cout<<ans.size()<<endl;
        for(auto u:ans)
        {
            cout<<u.first+1<<" "<<u.second+1<<endl;
        }
       //  cout<<str<<endl;
        ans.clear();

    }
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        string str;
        cin>>str;
        vector<pair<int,int>>ans;

        for(int i=0;i<n;)
        {
            if(str[i]=='(' && str[i+1]!=')')
            {
                for(int j=i+1;j<n;j++)
                {
                    if(str[j]==')')
                        {reverse(str.begin()+i+1,str.begin()+j+1);
                         ans.pb({i+1,j});
                         i+=2;
                        // cout<<"here"<<endl;
                         break;
                         }
                }
            }
            else if(str[i]==')')
            {
                for(int j=i+1;j<n;j++)
                {
                    if(str[j]=='(')
                    {
                        reverse(str.begin()+i,str.begin()+j+1);
                        ans.pb({i,j});
                        i+=2;
                        break;
                    }
                }
            }
            else i+=2;
        }
        int p=k-1;
        //cout<<str<<endl;
        reverse(str.begin()+2*p+1,str.begin()+n-1);
        ans.pb({2*p+1,n-2});
        cout<<ans.size()<<endl;
        for(auto u:ans)
        {
            cout<<u.first+1<<" "<<u.second+1<<endl;
        }
        ans.clear();

    }
}


#include<stdio.h>
int main()
{
    int no_of_steps, no_of_dirty_steps;
    scanf("%d %d", &no_of_steps, &no_of_dirty_steps);

    vector <int> dirty_steps(no_of_dirty_steps);
    for(int i = 0; i < no_of_dirty_steps; i++)
        scanf("%d", &dirty_steps[i]);

    sort(all(dirty_steps));

    bool is_possible = true;
    if(no_of_dirty_steps > 0)
    {
        if(dirty_steps.front() == 1 || dirty_steps.back() == no_of_steps)
        {
            is_possible = false;
        }
        else
        {
            for(int i = 2; i < no_of_dirty_steps; i++)
            {
                if(dirty_steps[i] == dirty_steps[i - 1] + 1 && dirty_steps[i] == dirty_steps[i - 2] + 2) //Three consecutive dirty steps
                {
                    is_possible = false;
                    break;
                }
            }
        }
    }

    printf(is_possible ? "YES\n" : "NO\n");
    return 0;
}


#include <stdio.h>
int main()
{
    long int n,s,c=0,flag=0,d=0,j;
    scanf ("%ld %ld",&n,&s);
    long int a[s],i;
    for (i=0;i<s;i++)
    {
        scanf("%ld",&a[i]);
    }
    for (j=0;j<s;j++)
    {
        c=0;
        d=0;
        if (a[j]==1 || a[j]==n)
        {
            flag=1;
            break;
        }
        else{
    for (i=0;i<s;i++)
    {
        if (a[j]!=a[i])
        {
            if (a[i]-a[j]==abs(1))
                c++;
            if (a[i]-a[j]==abs(2))
                d++;
        }
                if (c==d && c==1)
                {
                flag=1;
                break;
                }
    }
        }}
        if (flag==1)
            printf ("NO ");
        else printf ("YES ");
    return 0;
}


#include <stdio.h>
int main()
{
    long int n,s,c=0,flag=0,d=0,j;
    scanf ("%ld %ld",&n,&s);
    long int a[s],i;
    for (i=0;i<s;i++)
    {
        scanf("%ld",&a[i]);
    }
    for (j=0;j<s;j++)
    {
        c=0;
        d=0;
        if (a[j]==1 || a[j]==n)
        {
            flag=1;
            break;
        }
        else{
    for (i=0;i<s;i++)
    {
        if (a[j]!=a[i])
        {
            if (a[i]-a[j]==abs(1))
                c++;
            if (a[i]-a[j]==abs(2))
                d++;
        }
                if (c==d && c==1)
                {
                flag=1;
                break;
                }
    }
        }}
        if (flag==1)
            printf ("NO ");
        else printf ("YES k ");
    return 0;
}


#include <stdio.h>
int main()
{
    long int n,s,c=0,temp,j;
    scanf ("%ld %ld",&n,&s);
    long int a[n],i;
    for (i=0;i<s;i++)
    {
        scanf("%ld",&a[i]);
    }

    for (j=0;j<s;j++)
    {
    for (i=0;i<s;i++)
    {
        if (a[i]>a[i+1])
        {
            temp=a[i];
            a[i]=a[i+1];
            a[i+1]=temp;
        }
    }
    }

    for (i=0;i<s;i++)
    {
        if (i<=s-2)
        {
        if (a[i]==1 || (a[i+2]-a[i]==2))
            break;
        }
        else if (a[i]==n)
            break;
        c++;
    }
    if (c==s)
        printf ("YES");
    else printf ("NO");

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
/* Written by Nishant Mittal aka nishantwrp */
int main()
{
   long long int n,m;
   scanf("%lld %lld",&n,&m);
   int data[m];
   int i=0;
while(i<m) {
scanf("%d",&data[i]);
i++;
}
int j=0;
while(j<m) {
        int k = 0;
while(k<m-j-1) {
if (data[k] > data[k+1]){
int a,b;
a = data[k];
b = data[k+1];
data[k] = b;
data[k+1] = a;
}
k++;
}
j++;
}
int abc = 0;
int x=0;
while(x<m-2) {
if (data[x+1] == data[x] + 1 && data[x+2] == data[x] + 2) {
    abc = 1;
    break;
}
x++;
}
if (data[0] == 1 || data[m-1] == n || abc == 1) {
    printf("NO");
} else {
printf("YES");
}
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
/* Written by Nishant Mittal aka nishantwrp */
int main()
{
   long long int n,m;
   scanf("%lld %lld",&n,&m);
   int data[m];
   int i=0;
while(i<m) {
scanf("%d",&data[i]);
i++;
}
int j=0;
while(j<m) {
        int k = 0;
while(k<m-j-1) {
if (data[k] > data[k+1]){
int a,b;
a = data[k];
b = data[k+1];
data[k] = b;
data[k+1] = a;
}
k++;
}
j++;
}
int abc = 0;
int x=0;
while(x<m-2) {
if (data[x+1] == data[x] + 1 && data[x+2] == data[x] + 2) {
    abc = 1;
    break;
}
x++;
}
if (data[0] == 1 || data[m] == n || abc == 1) {
    printf("NO");
} else {
printf("YES");
}
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{long long int n, i, j;
int m, temp, second = 0;

scanf("%I64d %d",&n,&m);

int dirty[m];

for ( i = 0; i < m; i++)
{
    scanf("%d",&dirty[i]);

    if (dirty[i] == 1)
    {
        second = 1;
    }

}

if (second == 1)
{
    printf("NO");
    return 0;
}

for (i = 0; i < m; i++)
{
    for (j = 0; j < (m - 1 - i); j++)
    {
        if (dirty[j] > dirty[j+1])
        {
            temp = dirty[j];
            dirty[j] = dirty[j+1];
            dirty[j+1] = temp;
        }
    }
}

if (dirty[m-1] == n)
{
    printf("NO");
    return 0;
}

for ( i = 0; i < (m - 2); i++)
{
    if (dirty[i+1] == 1 + dirty[i])
    {
        if (dirty[i+2] == dirty[i]+2)
        {
            printf("NO");
            return 0;
        }
    }

}

printf("YES");

    return 0;
}


#include<stdio.h>
void mergesort(int arr[], int l, int r)
{
if (l < r)
{
int m = l+(r-l)/2;
mergesort(arr, l, m);
mergesort(arr, m+1,r);
merge(arr, l, m, r);
}
}
void merge(int arr[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
int L[n1], R[n2];
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1+ j];
i = 0;
j = 0;
k = l;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}

int main()
{
    int n,m,z=0,f=0;
    scanf("%d%d",&n,&m);
    int ar[n],br[m];
    for(int i=0;i<n;i++)
    ar[i]=i+1;
    for(int i=0;i<m;i++)
    scanf("%d",&br[i]);
    mergesort(br,0,m-1);
    if(br[0]==1||br[m-1]==n)
    printf("%s","NO");
    else
    {
    int cnt=0;
    for(int i=0;i<m;i++)
    {
    if(br[i]==ar[z])
    ar[z]=0;
    else
    i--;
    z++;
    }
    for(int i=0;i<n;i++)
    {
    if(ar[i]==0)
    {
    cnt++;
    if(cnt>2)
    {
    f=1;
    break;
    }
    }
    else
    cnt=0;
    }
    if(f==1)
    printf("%s","NO");
    else
    printf("%s","YES");
    }
    /*for(int i=0;i<n;i++)
    printf("%d ",ar[i]);*/
    return 0;
}


#include<stdio.h>
void mergesort(int arr[], int l, int r)
{
if (l < r)
{
int m = l+(r-l)/2;
mergesort(arr, l, m);
mergesort(arr, m+1,r);
merge(arr, l, m, r);
}
}
void merge(int arr[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
int L[n1], R[n2];
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1+ j];
i = 0;
j = 0;
k = l;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}

int main()
{
    int n,m,z=0,f=0;
    scanf("%d%d",&n,&m);
    int br[m];
    //for(int i=0;i<n;i++)
    //ar[i]=i+1;
    for(int i=0;i<m;i++)
    scanf("%d",&br[i]);
    mergesort(br,0,m-1);
   // for(int i=0;i<m;i++)
   // printf("%d ",br[i]);
    if(br[0]==1||br[m-1]==n)
    printf("%s","NO");
    else
    {
    int cnt=1;
    for(int i=0;i<m;i++)
    {
    if(br[i]+1==br[i+1])
    {
    cnt++;
    if(cnt>2)
    {
    f=1;
    break;
    }
    }
    else
    cnt=1;
    }
    /*for(int i=0;i<n;i++)
    {
    if(ar[i]==0)
    {
    cnt++;
    if(cnt>2)
    {
    f=1;
    break;
    }
    }
    else
    cnt=0;
    }*/
    if(f==1)
    printf("%s","NO");
    else
    printf("%s","YES");
    }
    /*for(int i=0;i<n;i++)
    printf("%d ",ar[i]);*/
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

/*
 *
 */
int main(int argc, char** argv) {
    long long l = 0, n, i, m;
    scanf("%I64d%I64d", &n, &m);
    long long d[m], s[n];
    for (l = 0; l < n; l++) {
        s[l] = 0;
    }
    for (i = 0; i < m; i++) {
        scanf("%I64d", &d[i]);
        s[d[i] - 1] = 1;
    }
    if (s[0] == 1 || s[n - 1] == 1) {
        printf("NO");
    } else {
        for (l = 2; l < n; l++) {
            if (s[l] == 1 && s[l - 1] == 1 && s[l - 2] == 1) {
                break;
            }
        }
        if (l == n || n < 3) {
            printf("YES");
        } else {
            printf("NO");
        }
    }
    return (EXIT_SUCCESS);
}


#include <stdio.h>
#include <stdlib.h>

/*
 *
 */

void merge(long long a[], int l, int m, int r) {
    int i, j, k;
    int n1 = m - l + 1;
    int n2 = r - m;

    long long L[n1], R[n2];
    for (i = 0; i < n1; i++) {
        L[i] = a[l + i];
    }
    for (i = 0; i < n2; i++) {
        R[i] = a[i + m + 1];
    }
    i = 0;
    j = 0;
    k = l;
    while (i < n1 && j < n2) {
        if (L[i] <= R[j]) {
            a[k] = L[i];
            i++;
        } else {
            a[k] = R[j];
            j++;
        }
        k++;
    }
    while (i < n1) {
        a[k] = L[i];
        i++;
        k++;
    }
    while (j < n2) {
        a[k] = R[j];
        j++;
        k++;
    }
}

void mergeSort(long long a[], int l, int r) {
    if (l < r) {
        int m = l + (r - l) / 2;
        mergeSort(a, l, m);
        mergeSort(a, m + 1, r);
        merge(a, l, m, r);
    }
}

int main(int argc, char** argv) {
    long long n;
    int i, m;
    scanf("%I64d%I64d", &n, &m);
    long long d[m];
    for (i = 0; i < m; i++) {
        scanf("%I64d", &d[i]);
    }
    mergeSort(d, 0, m - 1);
    if (d[0] == 1 || d[m - 1] == n) {
        printf("NO");
    } else {
        for (i = 2; i < m; i++) {
            if (d[i] == d[i - 1] + 1 && d[i - 1] == d[i - 2] + 1) {
                printf("NO");
                break;
            }
        }
        if (i == m) {
            printf("YES");
        }
    }
    return (EXIT_SUCCESS);
}


#include <stdio.h>
#include <stdlib.h>

/*
 *
 */
int main(int argc, char** argv) {
    long long l, k, n;
    int i, j, m;
    scanf("%I64d%d", &n, &m);
    long long d[m];
    int s[n];
    for (l = 0; l < n; l++) {
        s[l] = 0;
    }
    for (i = 0; i < m; i++) {
        scanf("%I64d", &d[i]);
        s[d[i] - 1] = 1;
    }
    if (s[0] == 1 || s[n - 1] == 1) {
        printf("NO");
    } else {
        for (l = 2; l < n; l++) {
            if (s[l] == 1 && s[l - 1] == 1 && s[l - 2] == 1) {
                break;
            }
        }
        if (l == n) {
            printf("YES");
        } else {
            printf("NO");
        }
    }
    return (EXIT_SUCCESS);
}


#include <stdio.h>
#include <stdlib.h>

/*
 *
 */
int main(int argc, char** argv) {
    long long l = 0, n, i, m;
    scanf("%I64d%I64d", &n, &m);
    long long d[m];
    int s[n];
    for (l = 0; l < n; l++) {
        s[l] = 0;
    }
    for (i = 0; i < m; i++) {
        scanf("%I64d", &d[i]);
        s[d[i] - 1] = 1;
    }
    if (s[0] == 1 || s[n - 1] == 1) {
        printf("NO");
    } else {
        for (l = 2; l < n; l++) {
            if (s[l] == 1 && s[l - 1] == 1 && s[l - 2] == 1) {
                break;
            }
        }
        if (l == n || n < 3) {
            printf("YES");
        } else {
            printf("NO");
        }
    }
    return (EXIT_SUCCESS);
}


#include <stdio.h>
#include <stdlib.h>

/*
 *
 */
int main(int argc, char** argv) {
    long long n, i, m;
    scanf("%I64d%I64d", &n, &m);
    long long d[m], s[n];
    for (i = 0; i < n; i++) {
        s[i] = 0;
    }
    for (i = 0; i < m; i++) {
        scanf("%I64d", &d[i]);
        s[d[i] - 1] = 1;
    }
    if (s[0] == 1 || s[n - 1] == 1) {
        printf("NO");
    } else {
        i = n;
        for (i = 3; i < n; i++) {
            if (s[i] == 1 && s[i - 1] == 1 && s[i - 2] == 1) {
                break;
            }
        }
        if (i == n || n < 3) {
            printf("YES");
        } else {
            printf("NO");
        }
    }
    return (EXIT_SUCCESS);
}


#include <stdio.h>
#include <stdlib.h>

/*
 *
 */
int main(int argc, char** argv) {
    long long l = 0, n, i, m;
    scanf("%I64d%d", &n, &m);
    long long d[m];
    int s[n];
    for (l = 0; l < n; l++) {
        s[l] = 0;
    }
    for (i = 0; i < m; i++) {
        scanf("%I64d", &d[i]);
        s[d[i] - 1] = 1;
    }
    if (s[0] == 1 || s[n - 1] == 1) {
        printf("NO");
    } else {
        for (l = 2; l < n; l++) {
            if (s[l] == 1 && s[l - 1] == 1 && s[l - 2] == 1) {
                break;
            }
        }
        if (l == n || n < 3) {
            printf("YES");
        } else {
            printf("NO");
        }
    }
    return (EXIT_SUCCESS);
}


#include <stdio.h>
#include <stdlib.h>

/*
 *
 */
int main(int argc, char** argv) {
    long long l, k, n;
    int i, j, m;
    scanf("%I64d%d", &n, &m);
    long long d[m];
    int s[n];
    for (l = 0; l < n; l++) {
        s[l] = 0;
    }
    for (i = 0; i < m; i++) {
        scanf("%I64d", &d[i]);
        s[d[i] - 1] = 1;
    }
    if (s[0] == 1 || s[n - 1] == 1) {
        printf("NO");
    } else {
        for (l = 2; l < n; l++) {
            if (s[l] == 1 && s[l - 1] == 1 && s[l - 2] == 1) {
                break;
            }
        }
        if (l == n) {
            printf("YES");
        } else {
            printf("NO");
        }
    }
    return (EXIT_SUCCESS);
}

ll


#include <stdio.h>
#include <stdlib.h>

/*
 *
 */
int main(int argc, char** argv) {
    long long l = 0, n;
    int i, m;
    scanf("%I64d%d", &n, &m);
    long long d[m];
    int s[n];
    for (l = 0; l < n; l++) {
        s[l] = 0;
    }
    for (i = 0; i < m; i++) {
        scanf("%I64d", &d[i]);
        s[d[i] - 1] = 1;
    }
    if (s[0] == 1 || s[n - 1] == 1) {
        printf("NO");
    } else {
        for (l = 2; l < n; l++) {
            if (s[l] == 1 && s[l - 1] == 1 && s[l - 2] == 1) {
                break;
            }
        }
        if (l == n || n < 3) {
            printf("YES");
        } else {
            printf("NO");
        }
    }
    return (EXIT_SUCCESS);
}


#include <stdio.h>
#include <stdlib.h>

/*
 *
 */

void merge(long long a[], int l, int m, int r) {
    int i, j, k;
    int n1 = m - l + 1;
    int n2 = r - m;

    long long L[n1], R[n2];
    for (i = 0; i < n1; i++) {
        L[i] = a[l + i];
    }
    for (i = 0; i < n2; i++) {
        R[i] = a[i + m + 1];
    }
    i = 0;
    j = 0;
    k = l;
    while (i < n1 && j < n2) {
        if (L[i] <= R[j]) {
            a[k] = L[i];
            i++;
        } else {
            a[k] = R[j];
            j++;
        }
        k++;
    }
    while (i < n1) {
        a[k] = L[i];
        i++;
        k++;
    }
    while (j < n2) {
        a[k] = R[j];
        j++;
        k++;
    }
}

void mergeSort(long long a[], int l, int r) {
    if (l < r) {
        int m = l + (r - l) / 2;
        mergeSort(a, l, m);
        mergeSort(a, m + 1, r);
        merge(a, l, m, r);
    }
}

int main(int argc, char** argv) {
    long long n;
    int i, m;
    scanf("%I64d%I64d", &n, &m);
    long long d[m];
    for (i = 0; i < m; i++) {
        scanf("%I64d", &d[i]);
    }
    mergeSort(d, 0, m - 1);
    if (d[0] == 1 || (int) d[m - 1] == (int) n) {
        printf("NO");
    } else {
        for (i = 2; i < m; i++) {
            if (d[i] == d[i - 1] + 1 && d[i - 1] == d[i - 2] + 1) {
                printf("NO");
                break;
            }
        }
        if (i == m) {
            printf("YES");
        }
    }
    return (EXIT_SUCCESS);
}


#include <stdio.h>
#include <stdlib.h>

/*
 *
 */

void merge(long a[], int l, int m, int r) {
    int i, j, k;
    int n1 = m - l + 1;
    int n2 = r - m;

    long L[n1], R[n2];
    for (i = 0; i < n1; i++) {
        L[i] = a[l + i];
    }
    for (i = 0; i < n2; i++) {
        R[i] = a[i + m + 1];
    }
    i = 0;
    j = 0;
    k = l;
    while (i < n1 && j < n2) {
        if (L[i] <= R[j]) {
            a[k] = L[i];
            i++;
        } else {
            a[k] = R[j];
            j++;
        }
        k++;
    }
    while (i < n1) {
        a[k] = L[i];
        i++;
        k++;
    }
    while (j < n2) {
        a[k] = R[j];
        j++;
        k++;
    }
}

void mergeSort(long a[], int l, int r) {
    if (l < r) {
        int m = l + (r - l) / 2;
        mergeSort(a, l, m);
        mergeSort(a, m + 1, r);
        merge(a, l, m, r);
    }
}

int main(int argc, char** argv) {
    long n;
    int i, m;
    scanf("%I64d%I64d", &n, &m);
    long d[m];
    for (i = 0; i < m; i++) {
        scanf("%I64d", &d[i]);
    }
    if(m == 0){
    	printf("YES");
    }else{
    mergeSort(d, 0, m - 1);
    if (d[0] == 1 || (int) d[m - 1] == (int) n) {
        printf("NO");
    } else {
        for (i = 2; i < m; i++) {
            if (d[i] == d[i - 1] + 1 && d[i - 1] == d[i - 2] + 1) {
                printf("NO");
                break;
            }
        }
        if (i == m) {
            printf("YES");
        }
    }}
    return (EXIT_SUCCESS);
}


#include <stdio.h>
#include <stdlib.h>

/*
 *
 */

void merge(long a[], int l, int m, int r) {
    int i, j, k;
    int n1 = m - l + 1;
    int n2 = r - m;

    long L[n1], R[n2];
    for (i = 0; i < n1; i++) {
        L[i] = a[l + i];
    }
    for (i = 0; i < n2; i++) {
        R[i] = a[i + m + 1];
    }
    i = 0;
    j = 0;
    k = l;
    while (i < n1 && j < n2) {
        if (L[i] <= R[j]) {
            a[k] = L[i];
            i++;
        } else {
            a[k] = R[j];
            j++;
        }
        k++;
    }
    while (i < n1) {
        a[k] = L[i];
        i++;
        k++;
    }
    while (j < n2) {
        a[k] = R[j];
        j++;
        k++;
    }
}

void mergeSort(long a[], int l, int r) {
    if (l < r) {
        int m = l + (r - l) / 2;
        mergeSort(a, l, m);
        mergeSort(a, m + 1, r);
        merge(a, l, m, r);
    }
}

int main(int argc, char** argv) {
    long n;
    int i, m;
    scanf("%I64d%I64d", &n, &m);
    long d[m];
    for (i = 0; i < m; i++) {
        scanf("%I64d", &d[i]);
    }
    mergeSort(d, 0, m - 1);
    if (d[0] == 1 || (int) d[m - 1] == (int) n) {
        printf("NO");
    } else {
        for (i = 2; i < m; i++) {
            if (d[i] == d[i - 1] + 1 && d[i - 1] == d[i - 2] + 1) {
                printf("NO");
                break;
            }
        }
        if (i == m) {
            printf("YES");
        }
    }
    return (EXIT_SUCCESS);
}


#include <stdio.h>
#include <stdlib.h>

/*
 *
 */

void merge(long a[], int l, int m, int r) {
    int i, j, k;
    int n1 = m - l + 1;
    int n2 = r - m;

    long L[n1], R[n2];
    for (i = 0; i < n1; i++) {
        L[i] = a[l + i];
    }
    for (i = 0; i < n2; i++) {
        R[i] = a[i + m + 1];
    }
    i = 0;
    j = 0;
    k = l;
    while (i < n1 && j < n2) {
        if (L[i] <= R[j]) {
            a[k] = L[i];
            i++;
        } else {
            a[k] = R[j];
            j++;
        }
        k++;
    }
    while (i < n1) {
        a[k] = L[i];
        i++;
        k++;
    }
    while (j < n2) {
        a[k] = R[j];
        j++;
        k++;
    }
}

void mergeSort(long a[], int l, int r) {
    if (l < r) {
        int m = l + (r - l) / 2;
        mergeSort(a, l, m);
        mergeSort(a, m + 1, r);
        merge(a, l, m, r);
    }
}

int main(int argc, char** argv) {
    long n;
    int i, m, check = 1;
    scanf("%I64d%I64d", &n, &m);
    long d[m];
    for (i = 0; i < m; i++) {
        scanf("%I64d", &d[i]);
    }
    if(m == 0){
    	printf("YES");
    }else{
    mergeSort(d, 0, m - 1);
    if (d[0] == 1 || d[m - 1] == n) {
        printf("NO");
    } else {
    	i = 1;
        for (i = 2; i < m; i++) {
            if (d[i] == d[i - 1] + 1 && d[i - 1] == d[i - 2] + 1) {
                printf("NO");
                check = 0;
                break;
            }
        }
        if (check) {
            printf("YES");
        }
    }}
    return (EXIT_SUCCESS);
}


#include<stdio.h>
#include<stdlib.h>
void main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int dirty_steps[m];
    int i=0,j;
    for(i=0;i<m;i++)
    {
        scanf("%d",&dirty_steps[i]);
    }
    for(i=0;i<m;i++)
    {
        for(j=i+1;j<m;j++)
        {
            int temp;
            if(dirty_steps[i]>dirty_steps[j])
                {
                    temp=dirty_steps[i];
                    dirty_steps[i]=dirty_steps[j];
                    dirty_steps[j]=temp;

                }

        }

    }
    if(dirty_steps[0]==1 || dirty_steps[m-1]==n)
    {
        printf("NO");
        exit(0);
    }
    else
    {
        for(i=0;i<m;i++)
        {
            if(dirty_steps[i+1]==(dirty_steps[i]+1 )&& dirty_steps[i+2]==dirty_steps[i+1]+1)
            {
                printf("NO");
                exit(0);
            }

        }

    }
    printf("YES");
    exit(0);
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,m,j,a,n;
    scanf("%d %d", &n, &m);
    int number[3000];
    for(i=0;i<m;i++)
    {
        scanf("%d",&number[i]);
    }

    for (i = 0; i < m; ++i)
    {
        for (j = i + 1; j < m; ++j)
        {
            if (number[i] > number[j])
            {
                a =  number[i];
                number[i] = number[j];
                number[j] = a;
            }
        }
    }

    if(m==0)
    {
       printf("YES");
    }
    else if(number[0]==1 || number[m-1]==n)
        printf("NO");

    else
    {

    for(j=0;j<m;j++)
    {
        if(number[j]+1==number[j+1])
        {
            if(number[j+1]+1==number[j+2])
            {
                printf("NO");
                break;
            }

        }
    }

    if(j==m)
            printf("YES");

    }
    return 0;
}


using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security;
using System.Text;

namespace Codeforces
{
    class Program
    {
        private static string readString() => Console.ReadLine();
        private static T readValue<T>() => (T)Convert.ChangeType(readString(), typeof(T));
        private static string[] readStrings(char delimiter = ' ') => readString().Split(delimiter);
        private static T[] readValues<T>(char delimiter = ' ') => readStrings(delimiter: delimiter).Select(x => (T)Convert.ChangeType(x, typeof(T))).ToArray();
        private static void write<T>(T s) => Console.WriteLine(s);

        private static int binarySearch<T>(List<T> list, T target) where T : IComparable
        {
            int l = 0, r = list.Count - 1;
            while (l <= r)
            {
                var m = (int)Math.Floor((double)(l + r) / 2);
                if (list[m].CompareTo(target) <= 0)
                    if (m == r || list[m + 1].CompareTo(target) > 0)
                        return m;
                    else
                        l = m + 1;
                else
                    r = m - 1;
            }
            return -1;
        }

        private static int quickSortPartition<T>(List<T> arr, int left, int right, Comparer<T> comparer)
        {
            T pivot = arr[left];
            while (true)
            {
                while (comparer.Compare(arr[left], pivot) < 0)
                    left++;
                while (comparer.Compare(arr[right], pivot) > 0)
                    right--;
                if (left < right)
                {
                    if (comparer.Compare(arr[left], arr[right]) == 0)
                        return right;

                    T temp = arr[left];
                    arr[left] = arr[right];
                    arr[right] = temp;
                }
                else
                    return right;
            }
        }
        private static void quickSort<T>(List<T> arr, int left, int right, Comparer<T> comparer)
        {
            if (left < right)
            {
                int pivot = quickSortPartition(arr, left, right, comparer);
                if (pivot > 1)
                    quickSort(arr, left, pivot - 1, comparer);
                if (pivot + 1 < right)
                    quickSort(arr, pivot + 1, right, comparer);
            }
        }

        private static void watermelon()
        {
            var w = readValue<int>();
            write(w >= 4 && w % 2 == 0 ? "YES" : "NO");
        }
        private static void wayTooLongWords()
        {
            var words = new List<string>();

            var n = readValue<int>();
            for (int i = 0; i < n; ++i)
                words.Add(readString());

            foreach (var word in words)
                write(word.Length <= 10 ? word : $"{word.First()}{word.Length - 2}{word.Last()}");
        }
        private static void team()
        {
            int solve = 0;

            var n = readValue<int>();
            for (int i = 0; i < n; ++i)
                if (readValues<int>().Where(x => x == 1).Count() > 1)
                    ++solve;

            write(solve);
        }
        private static void football()
        {
            var positions = readString();
            for (int i = 6; i < positions.Length; ++i)
                if (positions.Substring(i - 6, 6) == (positions[i] == '0' ? "000000" : "111111"))
                {
                    write("YES");
                    return;
                }
            write("NO");
        }
        private static void theatreSquare()
        {
            var sizes = readValues<int>();
            write((long)Math.Ceiling((double)sizes[0] / (double)sizes[2]) * (long)Math.Ceiling((double)sizes[1] / (double)sizes[2]));
        }
        private static void stringTask()
        {
            var Vowels = new HashSet<char> { 'a', 'o', 'y', 'e', 'u', 'i' };
            var sb = new StringBuilder();
            var s = readString().ToLower();
            foreach (var c in s)
                if (!Vowels.Contains(c))
                {
                    sb.Append('.');
                    sb.Append(c);
                }

            write(sb.ToString());
        }
        private static void taxi()
        {
            int taxis = 0;
            var groups = new Dictionary<int, int> { { 1, 0 }, { 2, 0 }, { 3, 0 } };

            readValue<int>();
            var groupSizes = readValues<int>();
            foreach (var size in groupSizes)
                if (size == 4)
                    ++taxis;
                else
                    groups[size] = groups[size] + 1;

            taxis += groups[3];
            groups[1] = groups[1] - Math.Min(groups[1], groups[3]);

            taxis += groups[2] / 2;
            if (groups[2] % 2 == 1)
            {
                ++taxis;
                groups[1] = groups[1] - 2;
            }

            if (groups[1] > 0)
                taxis += (int)Math.Ceiling((double)groups[1] / 4.0);

            write(taxis);
        }
        private static void fancyFence()
        {
            var a = readValue<int>();
            for (double i = 3.0; ; i += 1.0)
            {
                var x = (double)(i - 2.0) * 180.0 / i;
                if (a <= x)
                {
                    write(a < x ? "NO" : "YES");
                    break;
                }
            }
        }
        private static void interestingDrink()
        {
            readString();
            var prices = readValues<int>().OrderBy(x => x).ToList();
            var days = readValue<int>();
            for (int i = 0; i < days; ++i)
                write(binarySearch(prices, readValue<int>()) + 1);
        }
        private static void compilationErrors()
        {
            readString();
            Dictionary<int, int> errors = readValues<int>().GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count()), errors1 = new Dictionary<int, int>();
            foreach (var error in readValues<int>())
            {
                if (errors[error] > 1)
                    errors[error] = errors[error] - 1;
                else
                    errors.Remove(error);

                if (errors1.TryGetValue(error, out var count))
                    errors1[error] = count + 1;
                else
                    errors1.Add(error, 1);
            }
            write(errors.First().Key);

            foreach (var error in readValues<int>())
                if (errors1[error] > 1)
                    errors1[error] = errors1[error] - 1;
                else
                    errors1.Remove(error);
            write(errors1.First().Key);
        }
        private static void doubleCola()
        {
            var idToName = new Dictionary<int, string> { { 0, "Sheldon" }, { 1, "Leonard" }, { 2, "Penny" }, { 3, "Rajesh" }, { 4, "Howard" } };
            int n = readValue<int>(), i = 1;
            for (; n > i * 5; i *= 2)
                n -= i * 5;
            write(idToName[(n - 1) / i]);
        }
        private static void ilyaAndQueries()
        {
            var dic = new Dictionary<int, int>();
            var list = new List<Tuple<int, int>>();

            var s = readString();
            int start = 0, dicStart = 0;
            for (int j = 0; j < s.Length - 1; ++j)
                if (s[j] != s[j + 1])
                {
                    if (start < j)
                    {
                        list.Add(new Tuple<int, int>(start + 1, j + 1));
                        for (; dicStart < j + 1; ++dicStart)
                            dic.Add(dicStart, list.Count - 1);
                    }
                    start = j + 1;
                }
            if (start < s.Length - 1)
            {
                list.Add(new Tuple<int, int>(start + 1, s.Length));
                for (; dicStart < s.Length; ++dicStart)
                    dic.Add(dicStart, list.Count - 1);
            }

            var m = readValue<int>();
            for (int j = 0; j < m; ++j)
            {
                var q = readValues<int>();
                int l = q[0], r = q[1], result = 0;
                if (dic.TryGetValue(l, out var i))
                    for (; i < list.Count && r >= list[i].Item1; ++i)
                        if (l < list[i].Item2)
                            result += Math.Min(r, list[i].Item2) - Math.Max(l, list[i].Item1);
                write(result);
            }
        }
        private static void twoTeamsComposing()
        {
            var n = readValue<int>();
            var skills = readValues<int>().GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count());
        }
        #region Laptop
        private class Laptop
        {
            internal int Price { get; private set; }
            internal int Quality { get; private set; }
            internal Laptop(int[] values)
            {
                Price = values[0];
                Quality = values[1];
            }
        }
        private class Laptop_Comparer_Price : Comparer<Laptop>
        {
            public override int Compare([AllowNull] Laptop x, [AllowNull] Laptop y) => x.Price - y.Price;
        }
        private class Laptop_Comparer_Quality : Comparer<Laptop>
        {
            public override int Compare([AllowNull] Laptop x, [AllowNull] Laptop y) => x.Quality - y.Quality;
        }
        private static void laptops()
        {
            List<Laptop> prices = new List<Laptop>(), qualities = new List<Laptop>();
            var n = readValue<int>();
            for (int i = 0; i < n; ++i)
            {
                var laptop = new Laptop(readValues<int>());
                prices.Add(laptop);
                qualities.Add(laptop);
            }

            for (int i = 0; i < n; ++i)
                if (prices[i] != qualities[i])
                {
                    write("Happy Alex");
                    return;
                }
            write("Poor Alex");
        }
        #endregion
        private static void fence()
        {
            int k = readValues<int>()[1], minI = 0, currentH = 0;
            int[] h = readValues<int>();

            for (int i = 0; i < k; ++i)
                currentH += h[i];
            var minH = currentH;

            for (int i = 1; i < h.Length - k + 1; ++i)
            {
                currentH = currentH - h[i - 1] + h[i + k - 1];
                if (minH > currentH)
                {
                    minH = currentH;
                    minI = i;
                }
            }

            write(minI + 1);
        }
        #region serejaAndSuffixes
        private class SerejaL
        {
            internal int L { get; private set; }
            internal int Result;
            internal SerejaL(int l)
            {
                L = l;
            }
        }
        private class SerejaLComparerL : Comparer<SerejaL>
        {
            public override int Compare([AllowNull] SerejaL x, [AllowNull] SerejaL y) => x.L - y.L;
        }
        private static void serejaGetLs(int m, out List<SerejaL> listDistinct, out List<SerejaL> listOrdered)
        {
            listDistinct = new List<SerejaL>();
            listOrdered = new List<SerejaL>();
            var dic = new Dictionary<int, SerejaL>();
            for (int i = 0; i < m; ++i)
            {
                var l = readValue<int>() - 1;
                if (!dic.TryGetValue(l, out var item))
                {
                    item = new SerejaL(l);
                    dic.Add(l, item);
                    listDistinct.Add(item);
                }
                listOrdered.Add(item);
            }
            quickSort(listDistinct, 0, listDistinct.Count - 1, new SerejaLComparerL());
        }
        private static void serejaAndSuffixes()
        {
            var m = readValues<int>()[1];
            var a = readValues<int>();
            serejaGetLs(m, out var listDistinct, out var listOrdered);

            var distinct = new HashSet<int>();
            for (int i = listDistinct.Count - 1, j = a.Length - 1; i >= 0; --i)
            {
                for (; j >= listDistinct[i].L; --j)
                    if (!distinct.Contains(a[j]))
                        distinct.Add(a[j]);

                listDistinct[i].Result = distinct.Count;
            }

            foreach (var item in listOrdered)
                write(item.Result);
        }
        #endregion
        private static void bowWowTimetable()
        {
            string s = readString(), r = "1";
            int i = 1;
            for (; r.Length < s.Length; ++i, r = r + "00") ;
            if (r.Length > s.Length || !s.Substring(1).Contains('1'))
                write(i - 1);
            else
                write(i);
        }
        private static void digits()
        {
            readString();
            var numbers = readValues<int>().GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count());
            if (!numbers.ContainsKey(0))
            {
                write(-1);
                return;
            }
        }
        private static void lifeWithoutZeros()
        {
            long a = readValue<int>(), b = readValue<int>(), c = a + b;
            write(Convert.ToInt64(a.ToString().Replace("0", "")) + Convert.ToInt64(b.ToString().Replace("0", "")) == Convert.ToInt64(c.ToString().Replace("0", "")) ? "YES" : "NO");
        }
        private static void permutation()
        {
            var n = readValue<int>();
            var a = readValues<int>();
            write(n - a.Where(x => x <= n).Distinct().Count());
        }
        private static void hamsterFarm()
        {
            var n = readValues<long>()[0];
            var k = readValues<long>();
            int bestI = 0;
            for (int i = 1; i < k.Length; ++i)
                if (n % k[i] < n % k[bestI])
                    bestI = i;
            write($"{bestI + 1} {n / k[bestI]}");
        }
        private static void shellGame()
        {
            int n = readValue<int>(), x = readValue<int>();
            if (x == 1)
            {
                if (n % 2 == 1)
                    x = 0;
                else
                    x = 2;
                --n;
            }
            for (int i = n % 6; i > 0; --i)
                if (i % 2 == 1)
                {
                    if (x == 0)
                        x = 1;
                    else if (x == 1)
                        x = 0;
                }
                else if (x == 1)
                    x = 2;
                else if (x == 2)
                    x = 1;
            write(x);
        }
        private static void ACM_ICPC()
        {
            int[] a = readValues<int>(), score = new int[2], members = new int[2];
            for (int i1 = 0; i1 < 2; ++i1)
            {
                score[i1] = a[0];
                members[i1] = 1;
                for (int i2 = 0; i2 < 2; ++i2)
                {
                    score[i2] += a[1];
                    members[i2] += 1;
                    for (int i3 = 0; i3 < 2; ++i3)
                    {
                        score[i3] += a[2];
                        members[i3] += 1;
                        for (int i4 = 0; i4 < 2; ++i4)
                            if (members[i4] < 3)
                            {
                                score[i4] += a[3];
                                members[i4] += 1;
                                for (int i5 = 0; i5 < 2; ++i5)
                                    if (members[i5] < 3)
                                    {
                                        score[i5] += a[4];
                                        members[i5] += 1;
                                        for (int i6 = 0; i6 < 2; ++i6)
                                            if (members[i6] < 3)
                                            {
                                                score[i6] += a[5];
                                                members[i6] += 1;
                                                if (score[0] == score[1])
                                                {
                                                    write("YES");
                                                    return;
                                                }
                                                score[i6] -= a[5];
                                                members[i6] -= 1;
                                            }
                                        score[i5] -= a[4];
                                        members[i5] -= 1;
                                    }
                                score[i4] -= a[3];
                                members[i4] -= 1;
                            }
                        score[i3] -= a[2];
                        members[i3] -= 1;
                    }
                    score[i2] -= a[1];
                    members[i2] -= 1;
                }
                score[i1] = 0;
                members[i1] = 0;
            }
            write("NO");
        }
        private static void mex()
        {
            var x = readValues<int>()[1];
            var n = readValues<int>();
            write(x - n.Count(y => y < x) + (n.Contains(x) ? 1 : 0));
        }
        private static void minimumProduct()
        {
            var input = readValues<int>();
            int a = input[0], b = input[1], x = input[2], y = input[3], n = input[4], minA = Math.Min(a - x, n), minB = Math.Min(b - y, n);
            if (a - minA <= b - minB)
            {
                a -= minA;
                n -= minA;
            }
            else
            {
                b -= minB;
                n -= minB;
            }

            if (n > 0)
                if (a > x)
                    a -= Math.Min(a - x, n);
                else if (b > y)
                    b -= Math.Min(b - y, n);

            write((long)a * (long)b);
        }
        private static void shovelsAndSwords()
        {
            var input = readValues<int>();
            int a = input[0], b = input[1], result = 0;
            if (a > b)
            {
                var min = Math.Min(a - b, b);
                a -= min * 2;
                b -= min;
                result += min;
            }
            else if (b > a)
            {
                var min = Math.Min(b - a, a);
                a -= min;
                b -= min * 2;
                result += min;
            }
            int d = Math.Min(a / 3, b / 3);
            a -= d * 3;
            b -= d * 3;
            result += d * 2;
            if (a > 0 && b > 0 && (a > 1 || b > 1))
                ++result;
            write(result);
        }
        private static void matrixGame()
        {
            var input = readValues<int>();
            int n = input[0], m = input[1];
            HashSet<int> claimedRows = new HashSet<int>(), claimedColumns = new HashSet<int>();
            for (int i = 0; i < n; ++i)
            {
                input = readValues<int>();
                for (int j = 0; j < m; ++j)
                    if (input[j] == 1)
                    {
                        if (!claimedRows.Contains(i))
                            claimedRows.Add(i);
                        if (!claimedColumns.Contains(j))
                            claimedColumns.Add(j);
                    }
            }
            write(Math.Min(n - claimedRows.Count, m - claimedColumns.Count) % 2 == 0 ? "Vivek" : "Ashish");
        }
        private static void cinemaLine()
        {
            readString();
            var clerk = new Dictionary<int, int> { { 25, 0 }, { 50, 0 } };
            foreach (var a in readValues<int>())
                switch (a)
                {
                    case 25:
                        clerk[25] += 1;
                        break;
                    case 50:
                        if (clerk[25] > 0)
                        {
                            clerk[25] -= 1;
                            clerk[50] += 1;
                        }
                        else
                        {
                            write("NO");
                            return;
                        }
                        break;
                    default: // 100
                        if (clerk[50] > 0 && clerk[25] > 0)
                        {
                            clerk[25] -= 1;
                            clerk[50] -= 1;
                        }
                        else if (clerk[25] > 2)
                            clerk[25] -= 3;
                        else
                        {
                            write("NO");
                            return;
                        }
                        break;
                }
            write("YES");
        }
        private static void kindAnton()
        {
            readString();
            int[] a = readValues<int>(), b = readValues<int>();
            bool positive1 = false, negative1 = false;
            HashSet<int> positive = new HashSet<int>(), negative = new HashSet<int>();
            for (int i = 0; i < a.Length; ++i)
            {
                int diff = b[i] - a[i];
                if (((diff > 0 && !positive1) || (diff < 0 && !negative1)) && !(diff > 0 ? positive : negative).Any(x => diff % x == 0))
                {
                    write("NO");
                    return;
                }
                if (a[i] > 0)
                {
                    if (!positive1)
                        if (a[i] == 1)
                        {
                            positive1 = true;
                            if (negative1)
                            {
                                write("YES");
                                return;
                            }
                        }
                        else if (!positive.Contains(a[i]))
                            positive.Add(a[i]);
                }
                else if (a[i] < 0 && !negative1)
                    if (a[i] == -1)
                    {
                        negative1 = true;
                        if (positive1)
                        {
                            write("YES");
                            return;
                        }
                    }
                    else if (!negative.Contains(a[i]))
                        negative.Add(a[i]);
            }
            write("YES");
        }
        private static void staircases()
        {
            var n = readValues<int>()[0];
            var m = readValues<int>().OrderBy(x => x).ToList();
            if (m[0] == 1 || m[m.Count - 1] == n)
            {
                write("NO");
                return;
            }
            for (int i = 0; i < m.Count - 2; ++i)
                if (m[i] == m[i + 1] - 1 && m[i] == m[i + 2] - 2)
                {
                    write("NO");
                    return;
                }
            write("YES");
        }

        static void Main(string[] args)
        {
            //var t = readValue<int>();
            //for (int i = 0; i < t; ++i)
                staircases();
        }
    }
}