///***###                               بسم الله الرحمن الرحيم                            ###***///

/*
                    Author          : Borhan Uddin Rafi
                    University      : Begum Rokeya University,Rangpur.
                    Date            : 01 Dec,2020;
*/

///************************Start Of Template*************************///

#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#define Read_Fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define all(a) a.begin(),a.end()
#define f first
#define s second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define f0(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<n;i++)
#define f1n(i,n) for(i=1;i<=n;i++)
#define szf sizeof()
#define sz size()
#define ln length()
#define mem(x,r) memset(x,r,sizeof(x))
#define inf 1000000000000
using namespace std;
using ll=long long;
const int N=1e1+4;

//////graph////////

vector<int>circle;
bool vis[N];
int parent[N][N];
ll chk[N];
int color[N];
int tim[N];
int dis[N];
int position[N];
vector<int>adj[N];
vector<int>adj1[N];
vector<int>graph[N];
bool has_cycle;
int maxdis,maxnode,Totnode,depth=1;
bool ok;
queue<int>q;
stack<int>stk;
vector<int>solution;
int indegree[N];
int go[N];
int to[N];
ll x1,x2,x3,x4,x5,x6;
string ss;
int gn,gk;

//////graph////////

int brr[51][51];
int arr[51][51];

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    //Read_Fast;

    int t=1;
    cin>>t;
    int cas=0;
    while(t--)
    {
        int n,m,i,j,cnt=0,cnt1=0,cnt2=0,even=0,odd=0,len,k,r,l,z=0,x=0,y=0,flag=0,sum=0,tottal=0;
        int a=0,b=0,c=0,d=0,ans=0,rem,quot,zero=0,fst=0,null=0,snd=0,lst=0,rone=0,one=0,pos=0,neg=0,mn=INT_MAX,mx=INT_MIN;

        char ch;

        ////Time/////
        int h1,h2,m1,m2,h;

        ////motion ////
        int velo1,velo2,ac1,ac2,tim,hour,mint,sec;

        /////Graph///
        int node,edge,u,v,cost;
        int bst,wrst;
        double nd,ad,bd,cd,dd,xd,sumd=0.00;
        string str,str1="",str2="",str3="",strstore1="",strstore2="";

        //////Input Node //////

        cin>>n>>x;
        int arr[n+4];
        for(i=0; i<n; i++)
        {
            cin>>arr[i];
        }
        for(i=1; i<n; i++)
        {
            if(arr[i]<arr[i-1])
            {
                flag=1;
                break;
            }
        }
        if(flag)
        {
            flag=0;
            for(i=0; i<n; i++)
            {
                if(x>arr[i])
                {
                    swap(x,arr[i]);
                    cnt++;
                }
            }
            for(i=1; i<n; i++)
            {
                if(arr[i]<arr[i-1])
                {
                    flag=1;
                    break;
                }
            }
            if(flag)
            {
                cout<<-1<<endl;
            }
            else
            {
                cout<<cnt<<endl;
            }
        }
        else
        {
            cout<<'0'<<endl;
        }

    }

    return 0;

    //////***###            ٱلْحَمْدُ لِلَّٰهِ          ###***//////

}


///***###                               بسم الله الرحمن الرحيم                            ###***///

/*
                    Author          : Borhan Uddin Rafi
                    University      : Begum Rokeya University,Rangpur.
                    Date            : 01 Dec,2020;
*/

///************************Start Of Template*************************///

#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#define Read_Fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define all(a) a.begin(),a.end()
#define f first
#define s second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define f0(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<n;i++)
#define f1n(i,n) for(i=1;i<=n;i++)
#define szf sizeof()
#define sz size()
#define ln length()
#define mem(x,r) memset(x,r,sizeof(x))
#define inf 1000000000000
using namespace std;
using ll=long long;
const int N=1e1+4;

//////graph////////

vector<int>circle;
bool vis[N];
int parent[N][N];
ll chk[N];
int color[N];
int tim[N];
int dis[N];
int position[N];
vector<int>adj[N];
vector<int>adj1[N];
vector<int>graph[N];
bool has_cycle;
int maxdis,maxnode,Totnode,depth=1;
bool ok;
queue<int>q;
stack<int>stk;
vector<int>solution;
int indegree[N];
int go[N];
int to[N];
ll x1,x2,x3,x4,x5,x6;
string ss;
int gn,gk;

//////graph////////

int brr[51][51];
int arr[51][51];

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    //Read_Fast;

    int t=1;
    cin>>t;
    int cas=0;
    while(t--)
    {
        int n,m,i,j,cnt=0,cnt1=0,cnt2=0,even=0,odd=0,len,k,r,l,z=0,x=0,y=0,flag=0,sum=0,tottal=0;
        int a=0,b=0,c=0,d=0,ans=0,rem,quot,zero=0,fst=0,null=0,snd=0,lst=0,rone=0,one=0,pos=0,neg=0,mn=INT_MAX,mx=INT_MIN;

        char ch;

        ////Time/////
        int h1,h2,m1,m2,h;

        ////motion ////
        int velo1,velo2,ac1,ac2,tim,hour,mint,sec;

        /////Graph///
        int node,edge,u,v,cost;
        int bst,wrst;
        double nd,ad,bd,cd,dd,xd,sumd=0.00;
        string str,str1="",str2="",str3="",strstore1="",strstore2="";

        //////Input Node //////

        cin>>n>>x;
        int arr[n+4];
        for(i=0; i<n; i++)
        {
            cin>>arr[i];
        }
        while(1)
        {
            flag=0;
            for(i=1; i<n; i++)
            {
                if(arr[i]<arr[i-1])
                {
                    flag=1;
                    break;
                }
            }
            if(flag)
            {
                flag=0;
                for(i=0; i<n; i++)
                {
                    if(x<arr[i])
                    {
                        swap(x,arr[i]);
                        cnt++;
                        flag=1;
                        break;
                    }
                }

                if(!flag)
                {
                    cnt=-1;
                    break;
                }
            }
            else
            {
                break;
            }
        }
        cout<<cnt<<endl;

    }

    return 0;

    //////***###            ٱلْحَمْدُ لِلَّٰهِ          ###***//////

}


#include <bits/stdc++.h>

using namespace std;

void solve(){
    int res=0,tmp,n,x,a[1000],tg;
    cin >> n >> x;
    a[0]=0; a[n+1]=1000;
    tmp=n+1;
    for (int i=1; i<=n; i++) cin >> a[i];
    for (int i=1; i<=n; i++){
        if (a[i]<a[i-1]) {
            cout << -1 << endl;
            return;
        }
        if (a[i]>x) {
            tmp=i;
            break;
        }
    }
    while (tmp<=n){
        res++;
        tg=x;
        x=a[tmp];
        a[tmp]=tg;
        while (a[tmp]<=x) {
            tmp++;
            if (a[tmp]<a[tmp-1]){
                cout << -1 << endl;
                return;
            }
        }
    }
    cout << res << endl;
}

int main(){
    int t;
    for (cin >> t; t--; t>0) solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

void solve(){
    int res=0,tmp,n,x,a[1000],tg;
    cin >> n >> x;
    a[0]=0; a[n+1]=1000;
    for (int i=1; i<=n; i++) cin >> a[i];
    for (int i=1; i<=n; i++){
        if (a[i]<a[i-1]) {
            cout << -1 << endl;
            return;
        }
        if (a[i]>x) {
            tmp=i;
            break;
        }
    }
    while (tmp<=n){
        res++;
        tg=x;
        x=a[tmp];
        a[tmp]=tg;
        while (a[tmp]<=x) {
            tmp++;
            if (a[tmp]<a[tmp-1]){
                cout << -1 << endl;
                return;
            }
        }
    }
    cout << res << endl;
}

int main(){
    int t;
    for (cin >> t; t--; t>0) solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

void solve(){
    int res=0,tmp,n,x,a[1000],tg;
    cin >> n >> x;
    a[0]=0; a[n+1]=1000;
    tmp=n+1;
    for (int i=1; i<=n; i++) cin >> a[i];
    for (int i=1; i<=n; i++){
        if (a[i]<a[i-1]) {
            cout << -1 << endl;
            return;
        }
        if (a[i]>=x) {
            tmp=i;
            break;
        }
    }
    while (tmp<=n){
        int ok=0;
        for (int i=tmp+1; i<=n; i++)
            if (a[i]<a[i-1]) ok=1;
        if (ok==0) break;
        res++;
        tg=x;
        x=a[tmp];
        a[tmp]=tg;
        while (a[tmp]<=x) {
            tmp++;
            if (a[tmp]<a[tmp-1]){
                cout << -1 << endl;
                return;
            }
        }
    }
    cout << res << endl;
}

int main(){
    int t;
    for (cin >> t; t--; t>0) solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

void solve(){
    int res=0,tmp,n,x,a[1000],tg;
    cin >> n >> x;
    a[0]=0; a[n+1]=1000;
    tmp=n+1;
    for (int i=1; i<=n; i++) cin >> a[i];
    for (int i=1; i<=n; i++){
        if (a[i]<a[i-1]) {
            cout << -1 << endl;
            return;
        }
        if (a[i]>x) {
            tmp=i;
            break;
        }
    }
    while (tmp<=n){
        int ok=0;
        for (int i=tmp+1; i<=n; i++)
            if (a[i]<a[i-1]) ok=1;
        if (ok==0) break;
        res++;
        tg=x;
        x=a[tmp];
        a[tmp]=tg;
        while (a[tmp]<=x) {
            tmp++;
            if (a[tmp]<a[tmp-1]){
                cout << -1 << endl;
                return;
            }
        }
    }
    cout << res << endl;
}

int main(){
    int t;
    for (cin >> t; t--; t>0) solve();
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include <iomanip>
#include<math.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define fi first
#define se second
#define gap ' '
#define abs(x) ((x)>0?(x):-(x))
#define INF 1e18
#define mod 998244353
#define inf 1e9
#define pi 3.14159265358979
ll powr(ll m,ll n)
{
    if(m==1)
        return 1;
    if(n==0)
        return 1;
    if(n==1)
        return m%mod;
    if(n%2)
    {
        ll te=powr(m,n/2);
        return (((te*te)%mod)*(m%mod))%mod;
    }
    else
    {
        ll te=powr(m,n/2);
        return (te*te)%mod;
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tc=1;
    cin>>tc;
    int cs=0;

    while(tc--)
    {
       int n,x;
       cin>>n>>x;
       int a[n];
       vector<int> v;
       for(int i=0;i<n;i++)
       {
           cin>>a[i];
           v.pb(a[i]);
       }
       sort(v.begin(),v.end());
       int ok=1;
       int indx=0;
       for(int i=0;i<n;i++)
       {
           if(v[i]<=x)
           {
               if(v[i]!=a[i])
               {
                   ok=0;
                   break;
               }
           }
           else if(v[i]>x)
           {
               indx=i;
               break;
           }

       }
       if(!ok)
       {
           cout<<-1<<endl;
           continue;
       }
       int cntn=0;
       int cnt=0;
       for(int i=indx;i<n;i++)
       {
           if(a[i]>x)
           {
               swap(a[i],x);
               cnt++;
               for(int j=i;j<n-1;j++)
               {
                   if(a[j]>a[j+1])
                   {
                       cntn=1;
                       break;
                   }
               }
               if(!cntn) break;
           }
       }
       for(int i=1;i<n;i++)
       {
           if(a[i]<a[i-1])
           {
               ok=0;
               break;
           }
       }
      if(ok) cout<<cnt<<endl;
      else cout<<-1<<endl;

    }
}


#include<bits/stdc++.h>
#include<iostream>
#include <iomanip>
#include<math.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define fi first
#define se second
#define gap ' '
#define abs(x) ((x)>0?(x):-(x))
#define INF 1e18
#define mod 998244353
#define inf 1e9
#define pi 3.14159265358979
ll powr(ll m,ll n)
{
    if(m==1)
        return 1;
    if(n==0)
        return 1;
    if(n==1)
        return m%mod;
    if(n%2)
    {
        ll te=powr(m,n/2);
        return (((te*te)%mod)*(m%mod))%mod;
    }
    else
    {
        ll te=powr(m,n/2);
        return (te*te)%mod;
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tc=1;
    cin>>tc;
    int cs=0;

    while(tc--)
    {
       int n,x;
       cin>>n>>x;
       int a[n];
       vector<int> v;
       for(int i=0;i<n;i++)
       {
           cin>>a[i];
           v.pb(a[i]);
       }
       sort(v.begin(),v.end());
       int eql=0;
       for(int i=0;i<n;i++)
       {
           if(a[i]==v[i])
            eql++;
       }
       if(eql==n)
       {
           cout<<0<<endl;
           continue;
       }

       int ok=1;
       int indx=0;
       for(int i=0;i<n;i++)
       {
           if(v[i]<x)
           {
               if(v[i]!=a[i])
               {
                   ok=0;
                   break;
               }
           }
           else if(v[i]>=x)
           {
               indx=i;
               break;
           }

       }
       if(!ok)
       {
           cout<<-1<<endl;
           continue;
       }
       int cont=0;
       int cnt=0;
       //cout<<indx<<endl;
       for(int i=indx;i<n;i++)
       {
           cont=0;
           if(a[i]>x)
           {
               swap(a[i],x);
               cnt++;
               for(int j=i;j<n-1;j++)
               {
                   if(a[j]>a[j+1])
                   {
                       cont=1;
                       break;
                   }
               }
               if(!cont) break;
           }
       }
       //cout<<a[0]<<gap;
       for(int i=1;i<n;i++)
       {
           //cout<<a[i]<<gap;
           if(a[i]<a[i-1])
           {
               ok=0;
               break;
           }
       }
      if(ok) cout<<cnt<<endl;
      else cout<<-1<<endl;
      v.clear();

    }
}


#include<bits/stdc++.h>
#include<iostream>
#include <iomanip>
#include<math.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define fi first
#define se second
#define gap ' '
#define abs(x) ((x)>0?(x):-(x))
#define INF 1e18
#define mod 998244353
#define inf 1e9
#define pi 3.14159265358979
ll powr(ll m,ll n)
{
    if(m==1)
        return 1;
    if(n==0)
        return 1;
    if(n==1)
        return m%mod;
    if(n%2)
    {
        ll te=powr(m,n/2);
        return (((te*te)%mod)*(m%mod))%mod;
    }
    else
    {
        ll te=powr(m,n/2);
        return (te*te)%mod;
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tc=1;
    cin>>tc;
    int cs=0;

    while(tc--)
    {
       int n,x;
       cin>>n>>x;
       int a[n];
       vector<int> v;
       for(int i=0;i<n;i++)
       {
           cin>>a[i];
           v.pb(a[i]);
       }
       sort(v.begin(),v.end());
       int eql=0;
       for(int i=0;i<n;i++)
       {
           if(a[i]==v[i])
            eql++;
       }
       if(eql==n)
       {
           cout<<0<<endl;
           continue;
       }

       int ok=1;
       int indx=0;
       for(int i=0;i<n;i++)
       {
           if(v[i]<=x)
           {
               if(v[i]!=a[i])
               {
                   ok=0;
                   break;
               }
           }
           else if(v[i]>x)
           {
               indx=i;
               break;
           }

       }
       if(!ok)
       {
           cout<<-1<<endl;
           continue;
       }
       int cont=0;
       int cnt=0;
       //cout<<indx<<endl;
       for(int i=indx;i<n;i++)
       {
           cont=0;
           if(a[i]>x)
           {
               swap(a[i],x);
               cnt++;
               for(int j=i;j<n-1;j++)
               {
                   if(a[j]>a[j+1])
                   {
                       cont=1;
                       break;
                   }
               }
               if(!cont) break;
           }
       }
       //cout<<a[0]<<gap;
       for(int i=1;i<n;i++)
       {
           //cout<<a[i]<<gap;
           if(a[i]<a[i-1])
           {
               ok=0;
               break;
           }
       }
      if(ok) cout<<cnt<<endl;
      else cout<<-1<<endl;
      v.clear();

    }
}


#include<bits/stdc++.h>
#include<iostream>
#include <iomanip>
#include<math.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define fi first
#define se second
#define gap ' '
#define abs(x) ((x)>0?(x):-(x))
#define INF 1e18
#define mod 998244353
#define inf 1e9
#define pi 3.14159265358979
ll powr(ll m,ll n)
{
    if(m==1)
        return 1;
    if(n==0)
        return 1;
    if(n==1)
        return m%mod;
    if(n%2)
    {
        ll te=powr(m,n/2);
        return (((te*te)%mod)*(m%mod))%mod;
    }
    else
    {
        ll te=powr(m,n/2);
        return (te*te)%mod;
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tc=1;
    cin>>tc;
    int cs=0;

    while(tc--)
    {
       int n,x;
       cin>>n>>x;
       int a[n];
       vector<int> v;
       for(int i=0;i<n;i++)
       {
           cin>>a[i];
           v.pb(a[i]);
       }
       sort(v.begin(),v.end());
       int ok=1;
       int indx=0;
       for(int i=0;i<n;i++)
       {
           if(v[i]<=x)
           {
               if(v[i]!=a[i])
               {
                   ok=0;
                   break;
               }
           }
           else if(v[i]>x)
           {
               indx=i;
               break;
           }

       }
       if(!ok)
       {
           cout<<-1<<endl;
           continue;
       }
       int cntn=0;
       int cnt=0;
       for(int i=indx;i<n;i++)
       {
           if(a[i]>x)
           {
               swap(a[i],x);
               cnt++;
               for(int j=i+1;j<n-1;j++)
               {
                   if(a[j]>a[j+1])
                   {
                       cntn=1;
                       break;
                   }
               }
               if(!cntn) break;
           }
       }
       cout<<cnt<<endl;

    }
}


#include<bits/stdc++.h>
#include<iostream>
#include <iomanip>
#include<math.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define fi first
#define se second
#define gap ' '
#define abs(x) ((x)>0?(x):-(x))
#define INF 1e18
#define mod 998244353
#define inf 1e9
#define pi 3.14159265358979
ll powr(ll m,ll n)
{
    if(m==1)
        return 1;
    if(n==0)
        return 1;
    if(n==1)
        return m%mod;
    if(n%2)
    {
        ll te=powr(m,n/2);
        return (((te*te)%mod)*(m%mod))%mod;
    }
    else
    {
        ll te=powr(m,n/2);
        return (te*te)%mod;
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tc=1;
    cin>>tc;
    int cs=0;

    while(tc--)
    {
       int n,x;
       cin>>n>>x;
       int a[n];
       vector<int> v;
       for(int i=0;i<n;i++)
       {
           cin>>a[i];
           v.pb(a[i]);
       }
       sort(v.begin(),v.end());
       int eql=0;
       for(int i=0;i<n;i++)
       {
           if(a[i]==v[i])
            eql++;
       }
       if(eql==n)
       {
           cout<<0<<endl;
           continue;
       }
       int ok=1;
       int indx=0;
       for(int i=0;i<n;i++)
       {
           if(v[i]<=x)
           {
               if(v[i]!=a[i])
               {
                   ok=0;
                   break;
               }
           }
           else if(v[i]>x)
           {
               indx=i;
               break;
           }

       }
       if(!ok)
       {
           cout<<-1<<endl;
           continue;
       }
       int cntn=0;
       int cnt=0;
       for(int i=indx;i<n;i++)
       {
           cntn=0;
           if(a[i]>x)
           {
               swap(a[i],x);
               cnt++;
               for(int j=i;j<n-1;j++)
               {
                   if(a[j]>a[j+1])
                   {
                       cntn=1;
                       break;
                   }
               }
               if(!cntn) break;
           }
       }
       for(int i=1;i<n;i++)
       {
           if(a[i]<a[i-1])
           {
               ok=0;
               break;
           }
       }
      if(ok) cout<<cnt<<endl;
      else cout<<-1<<endl;

    }
}


#include <bits/stdc++.h>
using namespace std;
int a[505];
int main()
{
    int t,n,x,y;scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&x);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        int ans=0,b=1;
        while(b)
        {
            b=0;
            for(int i=1;i<=n;i++)
            {
                if(x<a[i])
                {
                    y=x;x=a[i];a[i]=y;b=1;ans++;break;
                }
            }
        }
        for(int i=2;i<=n;i++)
        {
            if(a[i-1]>a[i]) b=1;
        }
        if(b==1) cout<<-1<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[505];
int main()
{
    int t,n,x,y;scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&x);
        int ans=0,b=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            if(i!=1&&a[i-1]>a[i]) b=1;
        }
        while(b)
        {
            b=0;
            for(int i=1,z=0;i<=n;i++)
            {
                if(z&&a[i-1]>a[i])
                {
                    b=1;
                }
                if(!z&&x<a[i])
                {
                    y=x;x=a[i];a[i]=y;ans++;z=1;
                }
            }
        }
        for(int i=2;i<=n;i++)
        {
            if(a[i-1]>a[i]) b=1;
        }
        if(b==1) cout<<-1<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[505];
int main()
{
    int t,n,x,y;scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&x);
        int ans=0,b=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            if(i!=1&&a[i-1]>a[i]) b=1;
        }
        while(b)
        {
            b=0;
            for(int i=1;i<=n;i++)
            {
                if(x<a[i])
                {
                    y=x;x=a[i];a[i]=y;b=1;ans++;break;
                }
            }
        }
        for(int i=2;i<=n;i++)
        {
            if(a[i-1]>a[i]) b=1;
        }
        if(b==1) cout<<-1<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[505];
int main()
{
    int t,n,x,y;scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&x);
        int ans=0,b=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            if(i!=1&&a[i-1]>a[i]) b=1;
        }
        while(b)
        {
            b=0;
            for(int i=1,y=0;i<=n;i++)
            {
                if(y&&a[i-1]>a[i])
                {
                    b=1;
                }
                if(x<a[i])
                {
                    y=x;x=a[i];a[i]=y;ans++;y=1;
                }
            }
        }
        for(int i=2;i<=n;i++)
        {
            if(a[i-1]>a[i]) b=1;
        }
        if(b==1) cout<<-1<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int test;
    cin>>test;
    while(test--)
    {
        int n,x;
        cin>>n>>x;
        int i;
        int arr[n];
        for(i=0;i<n;i++)
        {
            cin>>arr[i];
        }

        int sort[n+1];
        sort[n] = 1;
        sort[n-1] = 1;
        for(i = n-2;i>=0;i--)
        {
            if(arr[i+1]>=arr[i] && sort[i+1]==1) sort[i] = 1;
            else sort[i] = 0;
        }

        int ans = 0;
        if(sort[0]==1)
        {
            cout<<0<<"\n";
            continue;
        }
        for(i=0;i<n;i++)
        {
            if(sort[i] && arr[i-1]<=arr[i]) break;

            if(arr[i]<=x && i==0)
            {
                ans = -1;
                break;
            }

            if(arr[i]<=x && i!=0 && arr[i-1]>arr[i])
            {
                ans = -1;
                break;
            }

            if(arr[i]>=x){
            int temp = arr[i];
            arr[i] = x;
            x = temp;
            ans++;
            }
            //cout<<x<<"\n";
        }

        for(i = n-2;i>=0;i--)
        {
            if(arr[i+1]>=arr[i] && sort[i+1]==1) sort[i] = 1;
            else sort[i] = 0;
        }
        if(ans==-1 || sort[0]) cout<<ans<<"\n";
        else cout<<"-1\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int test;
    cin>>test;
    while(test--)
    {
        int n,x;
        cin>>n>>x;
        int i;
        int arr[n];
        for(i=0;i<n;i++)
        {
            cin>>arr[i];
        }

        int sort[n+1];
        sort[n] = 1;
        sort[n-1] = 1;
        for(i = n-2;i>=0;i--)
        {
            if(arr[i+1]>=arr[i] && sort[i+1]==1) sort[i] = 1;
            else sort[i] = 0;
        }

        int ans = 0;
        if(sort[0]==1)
        {
            cout<<0<<"\n";
            continue;
        }
        for(i=0;i<n;i++)
        {
            if(sort[i] && arr[i-1]<=arr[i]) break;

            if(arr[i]<=x && i==0)
            {
                ans = -1;
                break;
            }

            if(arr[i]<=x && i!=0 && arr[i-1]>arr[i])
            {
                ans = -1;
                break;
            }

            if(arr[i]>x){
            int temp = arr[i];
            arr[i] = x;
            x = temp;
            ans++;
            }
            //cout<<x<<"\n";
        }

        for(i = n-2;i>=0;i--)
        {
            if(arr[i+1]>=arr[i] && sort[i+1]==1) sort[i] = 1;
            else sort[i] = 0;
        }
        if(ans==-1 || sort[0]) cout<<ans<<"\n";
        else cout<<"-1\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int test;
    cin>>test;
    while(test--)
    {
        int n,x;
        cin>>n>>x;
        int i;
        int arr[n];
        for(i=0;i<n;i++)
        {
            cin>>arr[i];
        }

        int sort[n+1];
        sort[n] = 1;
        sort[n-1] = 1;
        for(i = n-2;i>=0;i--)
        {
            if(arr[i+1]>=arr[i] && sort[i+1]==1) sort[i] = 1;
            else sort[i] = 0;
        }

        int ans = 0;
        if(sort[0]==1)
        {
            cout<<0<<"\n";
            continue;
        }
        for(i=0;i<n;i++)
        {
            if(sort[i] && arr[i-1]<=arr[i]) break;

            if(arr[i]<=x && i!=0 && arr[i-1]>arr[i])
            {
                ans = -1;
                break;
            }

            if(arr[i]>x){
            int temp = arr[i];
            arr[i] = x;
            x = temp;
            ans++;
            }
            //cout<<x<<"\n";
        }

        for(i = n-2;i>=0;i--)
        {
            if(arr[i+1]>=arr[i] && sort[i+1]==1) sort[i] = 1;
            else sort[i] = 0;
        }
        if(ans==-1 || sort[0]) cout<<ans<<"\n";
        else cout<<"-1\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int test;
    cin>>test;
    while(test--)
    {
        int n,x;
        cin>>n>>x;
        int i;
        int arr[n];
        for(i=0;i<n;i++)
        {
            cin>>arr[i];
        }

        int sort[n+1];
        sort[n] = 1;
        sort[n-1] = 1;
        for(i = n-2;i>=0;i--)
        {
            if(arr[i+1]>=arr[i] && sort[i+1]==1) sort[i] = 1;
            else sort[i] = 0;
        }

        int ans = 0;
        if(sort[0]==1)
        {
            cout<<0<<"\n";
            continue;
        }
        for(i=0;i<n;i++)
        {
            if(sort[i] && arr[i-1]<=arr[i]) break;

            if(arr[i]<=x && i!=0 && arr[i-1]>arr[i])
            {
                ans = -1;
                break;
            }
            if(arr[i]>=x){
            int temp = arr[i];
            arr[i] = x;
            x = temp;
            ans++;
            }
            //cout<<x<<"\n";
        }
        cout<<ans<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int test;
    cin>>test;
    while(test--)
    {
        int n,x;
        cin>>n>>x;
        int i;
        int arr[n];
        for(i=0;i<n;i++)
        {
            cin>>arr[i];
        }

        int sort[n+1];
        sort[n] = 1;
        sort[n-1] = 1;
        for(i = n-2;i>=0;i--)
        {
            if(arr[i+1]>=arr[i] && sort[i+1]==1) sort[i] = 1;
            else sort[i] = 0;
        }

        int ans = 0;
        if(sort[0]==1)
        {
            cout<<0<<"\n";
            continue;
        }
        for(i=0;i<n;i++)
        {
            if(sort[i] && arr[i-1]<=arr[i]) break;

            if(arr[i]<=x && i==0)
            {
                ans = -1;
                break;
            }

            if(arr[i]<=x && i!=0 && arr[i-1]>arr[i])
            {
                ans = -1;
                break;
            }

            if(arr[i]>=x){
            int temp = arr[i];
            arr[i] = x;
            x = temp;
            ans++;
            }
            //cout<<x<<"\n";
        }
        cout<<ans<<"\n";
    }
}


#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf 0x3f3f3f3f
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define X first
#define Y second
#define eps 1e-8
const int maxn = 2e5 + 10;
const int mod = 998244353;
using namespace std;

template<typename T1,typename T2>void ckmin(T1 &a,T2 b){if(a>b)a=b;}
template<typename T1,typename T2>void ckmax(T1 &a,T2 b){if(a<b)a=b;}
template<typename T1,typename T2>void addmo(T1 &a,T2 b){a+=b;if(a>=mod)a-=mod;}

int n,x,a[510];

void solve(){
    int f=1,ans=0;
    scanf("%d%d",&n,&x);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int ans=0;
    int flag=1;
    for(int i=1;i<=n-1;i++){
        int tt=1;
        for(int j=i;j<=n-1;j++){
            if(a[i]<=a[i+1]){
                tt++;
            }
            else
                break;
        }
        if(tt==n-i+1)
            break;
        if(a[i]>x){
            ans++;
            swap(a[i],x);
        }
    }
    int tt=1;
    for(int j=1;j<=n-1;j++){
        if(a[j]<=a[j+1]){
            tt++;
        }
        else
            break;
    }
    if(tt==n)
        cout<<ans<<endl;
    else
        cout<<-1<<endl;
}

signed main(){

    int T;
    scanf("%d",&T);
    while(T--)
        solve();
    // system("pause");
    return 0;
}


#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf 0x3f3f3f3f
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define X first
#define Y second
#define eps 1e-8
const int maxn = 2e5 + 10;
const int mod = 998244353;
using namespace std;

template<typename T1,typename T2>void ckmin(T1 &a,T2 b){if(a>b)a=b;}
template<typename T1,typename T2>void ckmax(T1 &a,T2 b){if(a<b)a=b;}
template<typename T1,typename T2>void addmo(T1 &a,T2 b){a+=b;if(a>=mod)a-=mod;}

int n,x,a[510];

void solve(){
    int f=1,ans=0;
    scanf("%d%d",&n,&x);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<n;i++){
        if(a[i]>a[i+1]){
            int p=-1;
            for(int j=i;j>=1;j--){
                if(a[j-1]<=x&&a[j]>x){
                    p=j;break;
                }
            }
            if(!~p){f=0;break;}
            for(int j=p;j<=i;j++){
                swap(a[j],x),ans++;
            }
            if(a[i]>a[i+1])f=0;
        }
    }
    printf("%d\n",f?ans:-1);
}

signed main(){

    int T;
    scanf("%d",&T);
    while(T--)
        solve();
    // system("pause");
    return 0;
}


#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf 0x3f3f3f3f
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define X first
#define Y second
#define eps 1e-8
const int maxn = 2e5 + 10;
const int mod = 998244353;
using namespace std;

template<typename T1,typename T2>void ckmin(T1 &a,T2 b){if(a>b)a=b;}
template<typename T1,typename T2>void ckmax(T1 &a,T2 b){if(a<b)a=b;}
template<typename T1,typename T2>void addmo(T1 &a,T2 b){a+=b;if(a>=mod)a-=mod;}

int n,x,a[510];

int cal(int x){
    int ans=1;
    for(int i=x;i<=n-1;i++){
        if(a[i]<=a[i+1])
            ans++;
        else break;
    }
    return ans;
}

void solve(){
    int f=1,ans=0;
    scanf("%d%d",&n,&x);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n-1;i++){
        if(cal(i)==n-i+1)
            break;
        if(a[i]>x){
            ans++;
            swap(a[i],x);
        }
    }
    if(cal(1)==n)
        cout<<ans<<endl;
    else
        cout<<-1<<endl;
}

signed main(){

    int T;
    scanf("%d",&T);
    while(T--)
        solve();
    // system("pause");
    return 0;
}


#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf 0x3f3f3f3f
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define X first
#define Y second
#define eps 1e-8
const int maxn = 2e5 + 10;
const int mod = 998244353;
using namespace std;

template<typename T1,typename T2>void ckmin(T1 &a,T2 b){if(a>b)a=b;}
template<typename T1,typename T2>void ckmax(T1 &a,T2 b){if(a<b)a=b;}
template<typename T1,typename T2>void addmo(T1 &a,T2 b){a+=b;if(a>=mod)a-=mod;}

int n,x,a[510];

void solve(){
    int f=1,ans=0;
    scanf("%d%d",&n,&x);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<n;i++){
        if(a[i]>a[i+1]){
            int p=-1;
            for(int j=i;j>=1;j--){
                if(a[j-1]<=x&&a[j]<x){
                    p=j;break;
                }
            }
            if(!~p){f=0;break;}
            for(int j=p;j<=i;j++){
                swap(a[j],x),ans++;
            }
            if(a[i]>a[i+1])f=0;
        }
    }
    printf("%d\n",f?ans:-1);
}

signed main(){

    int T;
    scanf("%d",&T);
    while(T--)
        solve();
    // system("pause");
    return 0;
}


#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf 0x3f3f3f3f
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define X first
#define Y second
#define eps 1e-8
const int maxn = 2e5 + 10;
const int mod = 998244353;
using namespace std;

template<typename T1,typename T2>void ckmin(T1 &a,T2 b){if(a>b)a=b;}
template<typename T1,typename T2>void ckmax(T1 &a,T2 b){if(a<b)a=b;}
template<typename T1,typename T2>void addmo(T1 &a,T2 b){a+=b;if(a>=mod)a-=mod;}

int n,x,a[510];

void solve(){
    int f=1,ans=0;
    scanf("%d%d",&n,&x);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n-1;i++){
        int tt=1;
        for(int j=i;j<=n-1;j++){
            if(a[i]<=a[i+1]){
                tt++;
            }
            else
                break;
        }
        if(tt==n-i+1)
            break;
        if(a[i]>x){
            ans++;
            swap(a[i],x);
        }
    }
    int tt=1;
    for(int j=1;j<=n-1;j++){
        if(a[j]<=a[j+1]){
            tt++;
        }
        else
            break;
    }
    if(tt==n)
        cout<<ans<<endl;
    else
        cout<<-1<<endl;
}

signed main(){

    int T;
    scanf("%d",&T);
    while(T--)
        solve();
    // system("pause");
    return 0;
}


#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf 0x3f3f3f3f
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define X first
#define Y second
#define eps 1e-8
const int maxn = 2e5 + 10;
const int mod = 998244353;
using namespace std;

template<typename T1,typename T2>void ckmin(T1 &a,T2 b){if(a>b)a=b;}
template<typename T1,typename T2>void ckmax(T1 &a,T2 b){if(a<b)a=b;}
template<typename T1,typename T2>void addmo(T1 &a,T2 b){a+=b;if(a>=mod)a-=mod;}

int n,x,a[510];

void solve(){
    int f=1,ans=0;
    scanf("%d%d",&n,&x);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<n;i++){
        if(a[i]>a[i+1]){
            int p=-1;
            for(int j=i;j>=1;j--){
                if(a[j-1]<=x&&a[j]>x){
                    p=j;break;
                }
            }
            if(!~p){f=0;break;}
            for(int j=p;j<=i;j++){
                if(a[j]>p)swap(a[j],x),ans++;
            }
            if(a[i]>a[i+1])f=0;
        }
    }
    printf("%d\n",f?ans:-1);
}

signed main(){

    int T;
    scanf("%d",&T);
    while(T--)
        solve();
    // system("pause");
    return 0;
}


#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf 0x3f3f3f3f
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define X first
#define Y second
#define eps 1e-8
const int maxn = 2e5 + 10;
const int mod = 998244353;
using namespace std;

template<typename T1,typename T2>void ckmin(T1 &a,T2 b){if(a>b)a=b;}
template<typename T1,typename T2>void ckmax(T1 &a,T2 b){if(a<b)a=b;}
template<typename T1,typename T2>void addmo(T1 &a,T2 b){a+=b;if(a>=mod)a-=mod;}

int n,x,a[510];

void solve(){
    int f=1,ans=0;
    scanf("%d%d",&n,&x);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<n;i++){
        if(a[i]>a[i+1]){
            int p=-1;
            for(int j=i;j>=1;j--){
                if(a[j-1]<=x){
                    p=j;break;
                }
            }
            for(int j=p;j<=i;j++){
                if(a[j]<=x)f=0;
                swap(a[j],x),ans++;
            }
            if(a[i]>a[i+1])f=0;
        }
    }
    printf("%d\n",f?ans:-1);
}

signed main(){

    int T;
    scanf("%d",&T);
    while(T--)
        solve();
    // system("pause");
    return 0;
}


#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf 0x3f3f3f3f
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define X first
#define Y second
#define eps 1e-8
const int maxn = 2e5 + 10;
const int mod = 998244353;
using namespace std;

template<typename T1,typename T2>void ckmin(T1 &a,T2 b){if(a>b)a=b;}
template<typename T1,typename T2>void ckmax(T1 &a,T2 b){if(a<b)a=b;}
template<typename T1,typename T2>void addmo(T1 &a,T2 b){a+=b;if(a>=mod)a-=mod;}

int n,x,a[510];

void solve(){
    int f=1,ans=0;
    scanf("%d%d",&n,&x);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<n;i++){
        if(a[i]>a[i+1]){
            int p=-1;
            for(int j=i;j>=1;j--){
                if(a[j-1]<=x){
                    p=j;break;
                }
            }
            for(int j=p;j<=i;j++){
                swap(a[j],x),ans++;
            }
            if(a[i]>a[i+1])f=0;
        }
    }
    printf("%d\n",f?ans:-1);
}

signed main(){

    int T;
    scanf("%d",&T);
    while(T--)
        solve();
    // system("pause");
    return 0;
}


#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf 0x3f3f3f3f
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define X first
#define Y second
#define eps 1e-8
const int maxn = 2e5 + 10;
const int mod = 998244353;
using namespace std;

template<typename T1,typename T2>void ckmin(T1 &a,T2 b){if(a>b)a=b;}
template<typename T1,typename T2>void ckmax(T1 &a,T2 b){if(a<b)a=b;}
template<typename T1,typename T2>void addmo(T1 &a,T2 b){a+=b;if(a>=mod)a-=mod;}

int n,x,a[510];

void solve(){
    int f=1,ans=0;
    scanf("%d%d",&n,&x);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<n;i++){
        if(a[i]>a[i+1]){
            int p=-1;
            for(int j=i;j>=1;j--){
                if(a[j-1]<=x&&a[j]>x){
                    p=j;break;
                }
            }
            if(!~p){f=0;break;}
            for(int j=p;j<=i;j++){
                if(a[j]>x)swap(a[j],x),ans++;
            }
            if(a[i]>a[i+1])f=0;
        }
    }
    printf("%d\n",f?ans:-1);
}

signed main(){

    int T;
    scanf("%d",&T);
    while(T--)
        solve();
    // system("pause");
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

auto Random_Address=[]{char*c;  c=new char;  delete c;  return uint64_t(c);};
uint64_t const SEED=chrono::steady_clock::now().time_since_epoch().count()*(Random_Address() bitor 1);
mt19937 Rng(SEED);

constexpr int Mask(int i){return 1<<i;}
constexpr int Getb(int x,int i){return x>>i bitand 1;}
template<size_t N> bitset<N> Bits(int x){return bitset<N>(x);}
template<class X,class Y> bool minimize(X&x,Y const&y){return y<x?x=y,1:0;}
template<class X,class Y> bool maximize(X&x,Y const&y){return y>x?x=y,1:0;}

int main(){
  cin.tie(nullptr)->sync_with_stdio(false);
  #ifndef ONLINE_JUDGE
  freopen("t.inp","r",stdin);freopen("t.out","w",stdout);
  #endif // ONLINE_JUDGE
  int Test;  cin>>Test;
  while(Test--) cout<<[]{
    int N,x;  cin>>N>>x;
    vector<int> a(N);  for(int i=0;i<N;i++) cin>>a[i];
    int res=0;
    for(int i=0;i<N;i++){
      if(i>0 and a[i]<a[i-1]){
        if(a[i]<x)
          return -1;
      }
      if(a[i]>x){
        swap(a[i],x);
        res++;
      }
    }
    return res;
  }()<<'\n';
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

auto Random_Address=[]{char*c;  c=new char;  delete c;  return uint64_t(c);};
uint64_t const SEED=chrono::steady_clock::now().time_since_epoch().count()*(Random_Address() bitor 1);
mt19937 Rng(SEED);

constexpr int Mask(int i){return 1<<i;}
constexpr int Getb(int x,int i){return x>>i bitand 1;}
template<size_t N> bitset<N> Bits(int x){return bitset<N>(x);}
template<class X,class Y> bool minimize(X&x,Y const&y){return y<x?x=y,1:0;}
template<class X,class Y> bool maximize(X&x,Y const&y){return y>x?x=y,1:0;}

int main(){
  cin.tie(nullptr)->sync_with_stdio(false);
  #ifndef ONLINE_JUDGE
  freopen("t.inp","r",stdin);freopen("t.out","w",stdout);
  #endif // ONLINE_JUDGE
  int Test;  cin>>Test;
  while(Test--) cout<<[]{
    int N,x;  cin>>N>>x;
    vector<int> a(N);  for(int i=0;i<N;i++) cin>>a[i];
    bool flag=true;
    for(int i=1;i<N;i++)
      if(a[i]<a[i-1])
        flag=false;
    if(flag)
      return 0;
    int res=0;
    for(int i=0;i<N;i++){
      if(i+1<N and a[i]>a[i+1]){
        if(a[i]<=x or a[i+1]<x)
          return -1;
      }
      if(a[i]>x){
        res++;
        swap(x,a[i]);
      }
    }
    return res;
  }()<<'\n';
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

auto Random_Address=[]{char*c;  c=new char;  delete c;  return uint64_t(c);};
uint64_t const SEED=chrono::steady_clock::now().time_since_epoch().count()*(Random_Address() bitor 1);
mt19937 Rng(SEED);

constexpr int Mask(int i){return 1<<i;}
constexpr int Getb(int x,int i){return x>>i bitand 1;}
template<size_t N> bitset<N> Bits(int x){return bitset<N>(x);}
template<class X,class Y> bool minimize(X&x,Y const&y){return y<x?x=y,1:0;}
template<class X,class Y> bool maximize(X&x,Y const&y){return y>x?x=y,1:0;}

int main(){
  cin.tie(nullptr)->sync_with_stdio(false);
  #ifndef ONLINE_JUDGE
  freopen("t.inp","r",stdin);freopen("t.out","w",stdout);
  #endif // ONLINE_JUDGE
  int Test;  cin>>Test;
  while(Test--) cout<<[]{
    int N,x;  cin>>N>>x;
    vector<int> a(N);  for(int i=0;i<N;i++) cin>>a[i];
    int res=0;
    for(int i=0;i<N;i++){
      int p=-1;
      for(int j=i+1;j<N;j++)
        if(a[j]<a[i] and(p==-1 or a[p]>a[j]))
          p=j;
      if(p!=-1){
        if(a[p]<x)
          return -1;
        if(a[p]<x)
          return -1;
      }
      if(a[i]>x){
        res++;
        swap(x,a[i]);
      }
    }
    return res;
  }()<<'\n';
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

auto Random_Address=[]{char*c;  c=new char;  delete c;  return uint64_t(c);};
uint64_t const SEED=chrono::steady_clock::now().time_since_epoch().count()*(Random_Address() bitor 1);
mt19937 Rng(SEED);

constexpr int Mask(int i){return 1<<i;}
constexpr int Getb(int x,int i){return x>>i bitand 1;}
template<size_t N> bitset<N> Bits(int x){return bitset<N>(x);}
template<class X,class Y> bool minimize(X&x,Y const&y){return y<x?x=y,1:0;}
template<class X,class Y> bool maximize(X&x,Y const&y){return y>x?x=y,1:0;}

int main(){
  cin.tie(nullptr)->sync_with_stdio(false);
  #ifndef ONLINE_JUDGE
  freopen("t.inp","r",stdin);freopen("t.out","w",stdout);
  #endif // ONLINE_JUDGE
  int Test;  cin>>Test;
  while(Test--) cout<<[]{
    int N,x;  cin>>N>>x;
    vector<int> a(N);  for(int i=0;i<N;i++) cin>>a[i];
    int res=0;
    for(int i=0;i<N;i++){
      if(i+1<N and a[i]>a[i+1]){
        if(a[i]<=x or a[i+1]<x)
          return -1;
      }
      if(a[i]>x){
        res++;
        swap(x,a[i]);
      }
    }
    return res;
  }()<<'\n';
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

auto Random_Address=[]{char*c;  c=new char;  delete c;  return uint64_t(c);};
uint64_t const SEED=chrono::steady_clock::now().time_since_epoch().count()*(Random_Address() bitor 1);
mt19937 Rng(SEED);

constexpr int Mask(int i){return 1<<i;}
constexpr int Getb(int x,int i){return x>>i bitand 1;}
template<size_t N> bitset<N> Bits(int x){return bitset<N>(x);}
template<class X,class Y> bool minimize(X&x,Y const&y){return y<x?x=y,1:0;}
template<class X,class Y> bool maximize(X&x,Y const&y){return y>x?x=y,1:0;}

int main(){
  cin.tie(nullptr)->sync_with_stdio(false);
  #ifndef ONLINE_JUDGE
  freopen("t.inp","r",stdin);freopen("t.out","w",stdout);
  #endif // ONLINE_JUDGE
  int Test;  cin>>Test;
  while(Test--) cout<<[]{
    int N,x;  cin>>N>>x;
    vector<int> a(N);  for(int i=0;i<N;i++) cin>>a[i];
    int res=0;
    for(int i=0;i<N;i++){
      if(i+1<N and a[i]>a[i+1]){
        if(a[i]<x or a[i+1]<x)
          return -1;
      }
      if(a[i]>x){
        res++;
        swap(x,a[i]);
      }
    }
    return res;
  }()<<'\n';
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

auto Random_Address=[]{char*c;  c=new char;  delete c;  return uint64_t(c);};
uint64_t const SEED=chrono::steady_clock::now().time_since_epoch().count()*(Random_Address() bitor 1);
mt19937 Rng(SEED);

constexpr int Mask(int i){return 1<<i;}
constexpr int Getb(int x,int i){return x>>i bitand 1;}
template<size_t N> bitset<N> Bits(int x){return bitset<N>(x);}
template<class X,class Y> bool minimize(X&x,Y const&y){return y<x?x=y,1:0;}
template<class X,class Y> bool maximize(X&x,Y const&y){return y>x?x=y,1:0;}

int main(){
  cin.tie(nullptr)->sync_with_stdio(false);
  #ifndef ONLINE_JUDGE
  freopen("t.inp","r",stdin);freopen("t.out","w",stdout);
  #endif // ONLINE_JUDGE
  int Test;  cin>>Test;
  while(Test--) cout<<[]{
    int N,x;  cin>>N>>x;
    vector<int> a(N+1);  for(int i=1;i<=N;i++) cin>>a[i];
    vector<vector<vector<int>>> f(N+1,vector<vector<int>>(505,vector<int>(2,1e9+7)));
    f[1][x][0]=0;
    if(a[1]>x)
      f[1][x][1]=1;
    for(int i=1;i<N;i++){
      for(int j=0;j<505;j++){
        for(int k=0;k<2;k++){
          if(f[i][j][k]!=1e9+7){
            int pre=a[i],_x=j;
            if(k)
              swap(pre,_x);
            if(pre>a[i+1]){
              if(pre>_x and a[i+1]>=_x and (i==1 or _x>a[i-1]))
                minimize(f[i+1][pre][0],f[i][j][k]+1);
            }
            else{
              minimize(f[i+1][_x][0],f[i][j][k]);
              if(a[i+1]>_x and _x>=pre)
                minimize(f[i+1][_x][1],f[i][j][k]+1);
            }
          }
        }
      }
    }
    int res=1e9+7;
    for(int j=0;j<505;j++)
      for(int k=0;k<2;k++)
      if(f[N][j][k]!=1e9+7)
        minimize(res,f[N][j][k]);
    if(res==1e9+7)
      return -1;
    return res;
  }()<<'\n';
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

auto Random_Address=[]{char*c;  c=new char;  delete c;  return uint64_t(c);};
uint64_t const SEED=chrono::steady_clock::now().time_since_epoch().count()*(Random_Address() bitor 1);
mt19937 Rng(SEED);

constexpr int Mask(int i){return 1<<i;}
constexpr int Getb(int x,int i){return x>>i bitand 1;}
template<size_t N> bitset<N> Bits(int x){return bitset<N>(x);}
template<class X,class Y> bool minimize(X&x,Y const&y){return y<x?x=y,1:0;}
template<class X,class Y> bool maximize(X&x,Y const&y){return y>x?x=y,1:0;}

int main(){
  cin.tie(nullptr)->sync_with_stdio(false);
  #ifndef ONLINE_JUDGE
  freopen("t.inp","r",stdin);freopen("t.out","w",stdout);
  #endif // ONLINE_JUDGE
  int Test;  cin>>Test;
  while(Test--) cout<<[]{
    int N,x;  cin>>N>>x;
    vector<int> a(N);  for(int i=0;i<N;i++) cin>>a[i];
    int res=0;
    for(int i=0;i<N;i++){
      int p=-1;
      for(int j=i+1;j<N;j++)
        if(a[j]<a[i] and(p==-1 or a[p]>a[j]))
          p=j;
      if(p!=-1){
        if(a[p]<x)
          return -1;
        if(a[i]<x)
          return -1;
      }
      if(a[i]>x){
        res++;
        swap(x,a[i]);
      }
    }
    return res;
  }()<<'\n';
  return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pp push
#define MOD 998244353
#define INF 1000000000000000
typedef long long ll;
using namespace std;
int a[1001];
// unordered_map<unordered_map<int,int>,int>dp[501];
void solve(int i,int j,int k){

}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while(t--){
		int n,x;
		cin >> n >> x;
		for(int i=1;i<=n;i++){
			cin >> a[i];
		}
		if(n==1){
			cout << 0 << '\n';
			continue;
		}
		int cnt=0;
		int flag=0;
		for(int i=2;i<=n;i++){
			if(a[i]<a[i-1]) flag++;
		}
		if(flag==0){
			cout << 0 << '\n';
			continue;
		}
		for(int i=1;i<=n;i++){
			if(a[i]>x){
				swap(a[i],x);
				cnt++;
			}
		}
		flag=0;
		for(int i=2;i<=n;i++){
			if(a[i]<a[i-1]){
				flag++;
				break;
			}
		}
		if(flag){
			cout << -1 << '\n';
		}
		else cout << cnt << '\n';
	}
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pp push
#define MOD 998244353
#define INF 1000000000000000
typedef long long ll;
using namespace std;
int a[1001];
// unordered_map<unordered_map<int,int>,int>dp[501];
void solve(int i,int j,int k){

}
int main(){
	// ios_base::sync_with_stdio(0);
	// cin.tie(0);
	// cout.tie(0);
	int t;
	cin >> t;
	while(t--){
		int n,x;
		cin >> n >> x;
		for(int i=1;i<=n;i++){
			cin >> a[i];
		}
		if(n==1){
			cout << 0 << '\n';
			continue;
		}
		int cnt=0;
		int flag=0;
		for(int i=2;i<=n;i++){
			if(a[i]<a[i-1]) flag++;
		}
		if(flag==0){
			cout << 0 << '\n';
			continue;
		}
		for(int i=1;i<=n;i++){
			int f=0;
			for(int j=i+1;j<=n;j++){
				if(a[j]<a[j-1]) f++''
			}
			if(f) break;
			if(a[i]>x){
				swap(a[i],x);
				cnt++;
			}
		}
		flag=0;
		for(int i=2;i<=n;i++){
			if(a[i]<a[i-1]){
				flag++;
				break;
			}
		}
		if(flag){
			cout << -1 << '\n';
		}
		else cout << cnt << '\n';
	}
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pp push
#define MOD 998244353
#define INF 1000000000000000
typedef long long ll;
using namespace std;
int a[1001];
// unordered_map<unordered_map<int,int>,int>dp[501];
void solve(int i,int j,int k){

}
int main(){
	// ios_base::sync_with_stdio(0);
	// cin.tie(0);
	// cout.tie(0);
	int t;
	cin >> t;
	while(t--){
		int n,x;
		cin >> n >> x;
		for(int i=1;i<=n;i++){
			cin >> a[i];
		}
		if(n==1){
			cout << 0 << '\n';
			continue;
		}
		int cnt=0;
		int flag=0;
		for(int i=2;i<=n;i++){
			if(a[i]<a[i-1]) flag++;
		}
		if(flag==0){
			cout << 0 << '\n';
			continue;
		}
		for(int i=1;i<=n;i++){
			int f=0;
			for(int j=i+1;j<=n;j++){
				if(a[j]<a[j-1]) f++;
			}
			if(f==0) break;
			if(a[i]>x){
				swap(a[i],x);
				cnt++;
			}
		}
		flag=0;
		for(int i=2;i<=n;i++){
			if(a[i]<a[i-1]){
				flag++;
				break;
			}
		}
		if(flag){
			cout << -1 << '\n';
		}
		else cout << cnt << '\n';
	}
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pp push
#define MOD 998244353
#define INF 1000000000000000
typedef long long ll;
using namespace std;
int a[1001];
// unordered_map<unordered_map<int,int>,int>dp[501];
void solve(int i,int j,int k){

}
int main(){
	// ios_base::sync_with_stdio(0);
	// cin.tie(0);
	// cout.tie(0);
	int t;
	cin >> t;
	while(t--){
		int n,x;
		cin >> n >> x;
		for(int i=1;i<=n;i++){
			cin >> a[i];
		}
		if(n==1){
			cout << 0 << '\n';
			continue;
		}
		int cnt=0;
		int flag=0;
		for(int i=2;i<=n;i++){
			if(a[i]<a[i-1]) flag++;
		}
		if(flag==0){
			cout << 0 << '\n';
			continue;
		}
		for(int i=1;i<=n;i++){
			int f=0;
			for(int j=i+1;j<=n;j++){
				if(a[j]<a[j-1]) f++;
			}
			if(f) break;
			if(a[i]>x){
				swap(a[i],x);
				cnt++;
			}
		}
		flag=0;
		for(int i=2;i<=n;i++){
			if(a[i]<a[i-1]){
				flag++;
				break;
			}
		}
		if(flag){
			cout << -1 << '\n';
		}
		else cout << cnt << '\n';
	}
}


#include <bits/stdc++.h>
using namespace std;
template <typename T>
void readin(T &x) {
    x = 0;
    char ch = getchar();
    T fh = 1;
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
    x *= fh;
}
template <typename T>
void wt(T x) {
    if (x > 9) wt(x / 10);
    putchar(x % 10 + 48);
}
template <typename T>
void writeln(T x, char ch) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    wt(x);
    putchar(ch);
}
const int N = 505;
int a[N];
int main() {
    int T;
    readin(T);
    while (T --) {
        int n, x;
        readin(n); readin(x);
        for (int i = 1; i <= n; i ++) {
            readin(a[i]);
        }
        bool onef = true;
        for (int i = 1; i <= n - 1; i ++) {
            if (a[i] > a[i + 1]) {
                onef = false;
                break;
            }
        }
        if (onef) {
            puts("0");
            continue;
        }
        a[n + 1] = 1e9;
        bool flg = false, rig = true;
        int las, sum = 0, pos = 1;
        while (!flg) {
            las = pos;
            for (; pos <= n; pos ++) {
                if (a[pos] > x) break;
            }
            for (int i = las; i < pos; i ++) {
                if (a[i] > a[i + 1]) {
                    rig = false;
                    flg = true;
                    break;
                }
            }
            for (int i = pos; i <= n; i ++) {
                if (a[i] < x) {
                    rig = false;
                    flg = true;
                    break;
                }
            }
            if (pos == n + 1) break;
            if (a[pos] > x && pos <= n) {
                sum ++;
                swap(a[pos], x);
            }
        }
        if (!rig) puts("-1");
        else writeln(sum, '\n');
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
template <typename T>
void readin(T &x) {
    x = 0;
    char ch = getchar();
    T fh = 1;
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
    x *= fh;
}
template <typename T>
void wt(T x) {
    if (x > 9) wt(x / 10);
    putchar(x % 10 + 48);
}
template <typename T>
void writeln(T x, char ch) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    wt(x);
    putchar(ch);
}
const int N = 505;
int a[N];
int main() {
    int T;
    readin(T);
    while (T --) {
        int n, x;
        readin(n); readin(x);
        for (int i = 1; i <= n; i ++) {
            readin(a[i]);
        }
        a[n + 1] = 1e9;
        bool onef = true;
        for (int i = 1; i <= n - 1; i ++) {
            if (a[i] > a[i + 1]) {
                onef = false;
                break;
            }
        }
        if (onef) {
            puts("0");
            continue;
        }
        bool flg = false, rig = true;
        int sum = 0, pos = 1;
        while (!flg) {
            while (a[pos] <= x) pos ++;
            for (int i = 1; i < pos; i ++) {
                if (a[i] > a[i + 1]) {
                    rig = false;
                    flg = true;
                    break;
                }
            }
            for (int i = pos; i <= n; i ++) {
                if (a[i] < x) {
                    rig = false;
                    flg = true;
                    break;
                }
            }
            flg = true;
            for (int i = pos; i <= n; i ++) {
                if (a[i] > a[i + 1]) {
                   flg = false;
                   break;
                }
            }
            if (flg) break;
            else {
                sum ++;
                swap(a[pos], x);
            }
        }
        if (!rig) puts("-1");
        else writeln(sum, '\n');
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
template <typename T>
void readin(T &x) {
    x = 0;
    char ch = getchar();
    T fh = 1;
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
    x *= fh;
}
template <typename T>
void wt(T x) {
    if (x > 9) wt(x / 10);
    putchar(x % 10 + 48);
}
template <typename T>
void writeln(T x, char ch) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    wt(x);
    putchar(ch);
}
const int N = 505;
int a[N];
int main() {
    int T;
    readin(T);
    while (T --) {
        int n, x;
        readin(n); readin(x);
        for (int i = 1; i <= n; i ++) {
            readin(a[i]);
        }
        bool onef = true;
        for (int i = 1; i <= n - 1; i ++) {
            if (a[i] > a[i + 1]) {
                onef = false;
                break;
            }
        }
        if (onef) {
            puts("0");
            continue;
        }
        a[n + 1] = 1e9;
        bool flg = false, rig = true;
        int sum = 0, pos = 1;
        while (!flg) {
            for (; pos <= n; pos ++) {
                if (a[pos] > x) break;
            }
            for (int i = 1; i < pos; i ++) {
                if (a[i] > a[i + 1]) {
                    rig = false;
                    flg = true;
                    break;
                }
            }
            for (int i = pos; i <= n; i ++) {
                if (a[i] < x) {
                    rig = false;
                    flg = true;
                    break;
                }
            }
            if (pos == n + 1) break;
            else {
                sum ++;
                swap(a[pos], x);
            }
        }
        if (!rig) puts("-1");
        else writeln(sum, '\n');
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
template <typename T>
void readin(T &x) {
    x = 0;
    char ch = getchar();
    T fh = 1;
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
    x *= fh;
}
template <typename T>
void wt(T x) {
    if (x > 9) wt(x / 10);
    putchar(x % 10 + 48);
}
template <typename T>
void writeln(T x, char ch) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    wt(x);
    putchar(ch);
}
const int N = 505;
int a[N];
int main() {
    int T;
    readin(T);
    while (T --) {
        int n, x;
        readin(n); readin(x);
        for (int i = 1; i <= n; i ++) {
            readin(a[i]);
        }
        a[n + 1] = 1e9;
        bool onef = true;
        for (int i = 1; i <= n - 1; i ++) {
            if (a[i] > a[i + 1]) {
                onef = false;
                break;
            }
        }
        if (onef) {
            puts("0");
            continue;
        }
        bool flg = false, rig = true;
        int sum = 0, pos = 1;
        while (!flg) {
            while (a[pos] <= x) pos ++;
            for (int i = 1; i < pos; i ++) {
                if (a[i] > a[i + 1]) {
                    rig = false;
                    flg = true;
                    break;
                }
            }
            for (int i = pos; i <= n; i ++) {
                if (a[i] < x) {
                    rig = false;
                    flg = true;
                    break;
                }
            }
            if (pos >= n ) break;
            else {
                sum ++;
                swap(a[pos], x);
            }
        }
        if (!rig) puts("-1");
        else writeln(sum, '\n');
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
template <typename T>
void readin(T &x) {
    x = 0;
    char ch = getchar();
    T fh = 1;
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
    x *= fh;
}
template <typename T>
void wt(T x) {
    if (x > 9) wt(x / 10);
    putchar(x % 10 + 48);
}
template <typename T>
void writeln(T x, char ch) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    wt(x);
    putchar(ch);
}
const int N = 505;
int a[N];
int main() {
    int T;
    readin(T);
    while (T --) {
        int n, x;
        readin(n); readin(x);
        for (int i = 1; i <= n; i ++) {
            readin(a[i]);
        }
        a[n + 1] = 1e9;
        bool onef = true;
        for (int i = 1; i <= n - 1; i ++) {
            if (a[i] > a[i + 1]) {
                onef = false;
                break;
            }
        }
        if (onef) {
            puts("0");
            continue;
        }
        bool flg = false, rig = true;
        int sum = 0, pos = 1;
        while (!flg) {
            while (a[pos] <= x) pos ++;
            for (int i = 1; i < pos; i ++) {
                if (a[i] > a[i + 1]) {
                    rig = false;
                    flg = true;
                    break;
                }
            }
            for (int i = pos; i <= n; i ++) {
                if (a[i] < x) {
                    rig = false;
                    flg = true;
                    break;
                }
            }
            flg = true;
            for (int i = pos; i <= n; i ++) {
                if (a[i] > a[i - 1]) {
                   flg = false;
                   break;
                }
            }
            if (flg) break;
            else {
                sum ++;
                swap(a[pos], x);
            }
        }
        if (!rig) puts("-1");
        else writeln(sum, '\n');
    }
    return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;
int t, n, x, a, b, lst, cnt, ans;
int main(){
	scanf("%d", &t);
	while(t--){
		scanf("%d%d", &n, &x);
		lst = b = 0; cnt = 0; ans = 0;
		int i;
		for(i = 1; i <= n; i++){
			scanf("%d", &a);
			if(b > a && lst > a)              { ans = -1; break; }
			if(b > a && (x >= a && lst <= a)) lst = a, ans += cnt, cnt = 0;
			if(b > a && (x < a && lst <= a))  lst = x, x = a, ans += cnt, cnt = 1;
			if(b <= a && x >= a)              lst = a;    // important: cannot put after (b<=a&&x<a), or the value of x will be revised
			if(b <= a && x < a)               lst = x, x = a, cnt++;
//			printf("a=%3d b=%3d lst=%3d x=%3d cnt=%3d ans=%3d\n", a, b, lst, x, cnt, ans);
			b = a;
		}
		for(i++; i <= n; i++) scanf("%d", &a);	// important
		printf("%d\n", ans);
	}
	return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;
int t, n, x, a[1100], ans;
int check(){
	for(int i = 2; i <= n; i++)
	    if(a[i-1] > a[i]) return 0;
	return 1;
}
int main(){
	scanf("%d", &t);
	while(t--){
		ans = 0;
		scanf("%d%d", &n, &x);
		for(int i = 1; i <= n; i++)
		    scanf("%d", &a[i]);
		if(check()){ printf("0\n"); continue; }
		for(int i = 1; i <= n; i++)
			if(a[i] > x){
				int tmp = x; x = a[i]; a[i] = tmp;  ans++;
				if(check()) printf("%d\n", ans);
			}
		if(!check()) printf("-1\n");
	}
	return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;
int t, n, x, a, b, lst, cnt, ans;
int main(){
	scanf("%d", &t);
	while(t--){
		scanf("%d%d", &n, &x);
		lst = b = 0; cnt = 0; ans = 0;
		for(int i = 1; i <= n; i++){
			scanf("%d", &a);
			/*b < a : 1) x < a && x >= lst -->exchange(backup)
			  b == a : do nothing
			  b > a : 1) lst > a: no solution		(there's a obvious rule: lst <= x)
			          2) x >= a && lst <= a: forced exchange (before a, except a)
					  3) x < a && lst <= a: forced exchange*/
			if(b < a && x < a)                lst = x, x = a, cnt++;
			if(b > a && lst > a)              { ans = -1; break; }
			if(b > a && (x >= a && lst <= a)) lst = a, ans += cnt, cnt = 0;
			if(b > a && (x < a && lst <= a))  lst = x, x = a, ans += cnt, cnt = 1;
			if(lst == x) cnt--;
			b = a;
		}
		printf("%d\n", ans);
	}
	return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;
int t, n, x, a, b, lst, cnt, ans;
int main(){
	scanf("%d", &t);
	while(t--){
		scanf("%d%d", &n, &x);
		lst = b = 0; cnt = 0; ans = 0;
		int i;
		for(i = 1; i <= n; i++){
			scanf("%d", &a);
			if(b > a && lst > a)              { ans = -1; break; }
			if(b > a && (x >= a && lst <= a)) lst = a, ans += cnt, cnt = 0;
			if(b > a && (x < a && lst <= a))  lst = x, x = a, ans += cnt, cnt = 1;
			if(b <= a && x >= a)              lst = a;    // important: cannot put after (b<=a&&x<a), or the value of x will be revised
			if(b <= a && x < a)               lst = x, x = a, cnt++;
//			printf("a=%3d b=%3d lst=%3d x=%3d cnt=%3d ans=%3d\n", a, b, lst, x, cnt, ans);
			b = a;
		}
		for(i++; i <= n; i++) scanf("%d", &a);	// important
		printf("%d\n", ans);
	}
	return 0;
}
/*
hack:
7 2
3 3 3 3 3 3 2
8 3
1 3 2 2 4 5 8 6
*/


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5, INF = 0x3f3f3f3f;
#define mod int(1e9+7)
#define pi acos(-1.0)
int vis[maxn],sta[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    string s;
    cin>>s;
    int flag=0,top=0;
    for(int i=0;i<n;i++){
        sta[top++]=i;
        if(top>=2&&s[sta[top-1]]==')'&&s[sta[top-2]]=='('){
            vis[sta[top-1]]=vis[sta[top-2]]=1;
            top-=2;
            flag++;
            if(flag==n/4)break;
        }
    }
    for(int i=0;i<n;i++){
        if(vis[i])printf("0");
        else printf("1");
    }

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5, INF = 0x3f3f3f3f;
#define mod int(1e9+7)
#define pi acos(-1.0)
int vis[maxn],sta[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    string s;
    cin>>s;
    int dep=0,tmp=0;
    for(int i=0;i<n;i++){
        if(s[i]=='(')tmp++;
        else tmp--;
        dep=max(tmp,dep);
    }
    //cout<<dep<<endl;
    dep=(dep+1)/2,tmp=0;
    for(int i=0;i<n;i++){
         if(s[i]=='(')tmp++;
         if(tmp>dep)vis[i]=1;
         else vis[i]=0;
         if(s[i]==')')tmp--;
    }
    for(int i=0;i<n;i++){
        cout<<vis[i];
    }

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5, INF = 0x3f3f3f3f;
#define mod int(1e9+7)
#define pi acos(-1.0)
int vis[maxn],sta[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    string s;
    cin>>s;
    int flag=0,top=0;
    for(int i=0;i<n;i++){
        sta[top++]=s[i];
        if(top>=2&&sta[top-1]==')'&&sta[top-2]=='('){
            flag^=1;
            vis[i]=vis[i-1]=flag;
            top-=2;
        }
    }
    for(int i=0;i<n;i++){
        if(vis[i])printf("0");
        else printf("1");
    }

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5, INF = 0x3f3f3f3f;
#define mod int(1e9+7)
#define pi acos(-1.0)
int vis[maxn],sta[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    string s;
    cin>>s;
    int flag=0,top=0;
    for(int i=0;i<n;i++){
        sta[top++]=s[i];
        if(top>=2&&sta[top-1]==')'&&sta[top-2]=='('){
            vis[i]=vis[i-1]=1;
            flag++;
            if(flag==n/4)break;
        }
    }
    for(int i=0;i<n;i++){
        if(vis[i])printf("0");
        else printf("1");
    }

}


    #include<bits/stdc++.h>
    #define mpa make_pair
    #define pb push_back
    using namespace std;

    int main(){
        int n;
        cin >> n;
        string s;
        cin >> s;
        int dep = 0;
        int mdep = 0;
        stack<int>stk;

        string res = "";

        //map< int,vector < pair<int,int> > >mp;
        vector< vector<pair<int,int> > >mp;
        mp.resize(n+1);
        for(int i=0 ; i<n ; i++){
            res = res + '0';
            if(s[i] == '('){
                stk.push(i);
                dep++;
            }
            else{
                mp[dep].pb(mpa(stk.top(),i));
                dep--;
                stk.pop();
            }
            mdep = max(mdep,dep);
        }

        //cout << "#";
        int tar = mdep/2;

        for (int i=tar+1 ; i<n ; i++){
            int len = mp[i].size();
            for(int j=0 ; j<len ; j++){
                res[mp[i][j].first] = '1';
                res[mp[i][j].second] = '1';
            }
        }
        cout << res << "\n";
        return 0;
    }


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

    int main(){
        int n;
        cin >> n;
        string s;
        cin >> s;
        int dep = 0;
        int mdep = 0;
        stack<int>stk;

        string res = "";

        map< int,vector < pair<int,int> > >mp;
        for(int i=0 ; i<n ; i++){
            res = res + "0";
            if(s[i] == '('){
                stk.push(i);
                dep++;
            }
            else{
                mp[dep].pb({stk.top(),i});
                dep--;
                stk.pop();
            }
            mdep = ((mdep>dep)?mdep:dep);
        }

        //cout << "#";
        int tar = mdep/2;

        for (int i=tar+1 ; i<n ; i++){
            int len = mp[i].size();
            for(int j=0 ; j<len ; j++){
                res[mp[i][j].first] = '1';
                res[mp[i][j].second] = '1';
            }
        }
        cout << res << "\n";
        return 0;
    }


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
#define int            		long long
#define x              		first
#define y              		second
#define all(aaa)       		(aaa).begin(),(aaa).end()
#define REP(i,sss,eee) 		for(int i=sss;i<=eee;++i)
#define pb             		push_back
#define pii            		pair<int,int>
#define vi             		vector<int>
#define speed          		ios_base::sync_with_stdio(0);cin.tie(0);
#define N              		1000000007
#define inf					1000000000000000000
using namespace __gnu_pbds;
using namespace std;
template <class T>
T MAX(T a, T b){return ((a>b)?a:b);}
template <class T>
T MIN(T a, T b){return ((a<b)?a:b);}
template <class T>
T MOD(T a){return ((a>=0)?a:(-1*a));}
template <class T>
void SWAP(T &a,T &b){T temp=a;a=b;b=temp;}

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;//for multiset use less_equal above

inline int ex(int a, int b){
	if(b==0||a==1){return 1;}
	if(a==0||b==1){return a;}
	int tmp=ex(a,(b/2));
	if(b%2){return ((((tmp*tmp)%N)*a)%N);}
	else{return ((tmp*tmp)%N);}
}
inline int inv(int k){
	if(k==1){return 1;}
	else{return ex(k,N-2);}
}
/*****************default********************/
int solve()
{
	int n;cin>>n;
	string str;cin>>str;
	int pres=0,max=0;
	for(auto it:str)
	{
		if(it=='('){++pres;}
		else{--pres;}
		max=MAX(max,pres);
	}
	int tar=max/2,begcnt=0;pres=0;
	string fin="";
	for(auto it:str)
	{
		if(it=='(')
		{
			pres++;
			if(pres<=tar)
			{
				begcnt++;
				fin+='1';
			}
			else
			{
				fin+='0';
			}
		}
		else
		{
			pres--;
			if(begcnt>0)
			{
				--begcnt;
				fin+='1';
			}
			else{fin+='0';}
		}
	}
	cout<<fin<<"\n";
}
signed main(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
	speed
	int tt=1;
	//cin>>tt;
	while(tt--)
	{
		solve();
	}
	return 0;
}


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

    int main(){
    	#ifndef ONLINE_JUDGE
    	freopen("input.txt","r",stdin);
    	freopen("output.txt","w",stdout);
    	#endif
        int n;
        cin >> n;
        string s;
        cin >> s;
        int dep = 0;
        int mdep = 0;
        stack<int>stk;

        string res = "";

        //map< int,vector < pair<int,int> > >mp;
        vector< vector<pair<int,int> > >mp;
        mp.resize(n+1);
        for(int i=0 ; i<n ; i++){
            res = res + "0";
            if(s[i] == '('){
                stk.push(i);
                dep++;
            }
            else{
                mp[dep].pb({stk.top(),i});
                dep--;
                stk.pop();
            }
            mdep = max(mdep,dep);
        }

        //cout << "#";
        int tar = mdep/2;

        for (int i=tar+1 ; i<n ; i++){
            int len = mp[i].size();
            for(int j=0 ; j<len ; j++){
                res[mp[i][j].first] = '1';
                res[mp[i][j].second] = '1';
            }
        }
        cout << res << "\n";
        return 0;
    }


    #include<bits/stdc++.h>
    #define mpa make_pair
    #define pb push_back
    using namespace std;

    int main(){
        int n;
        cin >> n;
        string s;
        cin >> s;
        int dep = 0;
        int mdep = 0;
        stack<int>stk;

        string res = "";

        //map< int,vector < pair<int,int> > >mp;
        vector< vector<pair<int,int> > >mp;
        mp.resize(n+1);
        for(int i=0 ; i<n ; i++){
            res = res+'0';
            if(s[i] == '('){
                stk.push(i);
                dep++;
            }
            else{
                mp[dep].pb(mpa(stk.top(),i));
                dep--;
                stk.pop();
            }
            mdep = max(mdep,dep);
        }

        //cout << "#";
        int tar = mdep/2;

        for (int i=tar+1 ; i<n ; i++){
            int len = mp[i].size();
            for(int j=0 ; j<len ; j++){
                res[mp[i][j].first] = '1';
                res[mp[i][j].second] = '1';
            }
        }
        cout << res << "\n";
        return 0;
    }


    #include<bits/stdc++.h>
    #define mpa make_pair
    #define pb push_back
    using namespace std;

    int main(){
        int n;
        cin >> n;
        string s;
        cin >> s;
        int dep = 0;
        int mdep = 0;
        stack<int>stk;

        string res = "";

        //map< int,vector < pair<int,int> > >mp;
        vector< vector<pair<int,int> > >mp;
        mp.resize(n+1);
        for(int i=0 ; i<n ; i++){
            res += '0';
            if(s[i] == '('){
                stk.push(i);
                dep++;
            }
            else{
                mp[dep].pb(mpa(stk.top(),i));
                dep--;
                stk.pop();
            }
            mdep = max(mdep,dep);
        }

        //cout << "#";
        int tar = mdep/2;

        for (int i=tar+1 ; i<n ; i++){
            int len = mp[i].size();
            for(int j=0 ; j<len ; j++){
                res[mp[i][j].first] = '1';
                res[mp[i][j].second] = '1';
            }
        }
        cout << res << "\n";
        return 0;
    }


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
#define int            		long long
#define x              		first
#define y              		second
#define all(aaa)       		(aaa).begin(),(aaa).end()
#define REP(i,sss,eee) 		for(int i=sss;i<=eee;++i)
#define pb             		push_back
#define pii            		pair<int,int>
#define vi             		vector<int>
#define speed          		ios_base::sync_with_stdio(0);cin.tie(0);
#define N              		1000000007
#define inf					1000000000000000000
using namespace __gnu_pbds;
using namespace std;
template <class T>
T MAX(T a, T b){return ((a>b)?a:b);}
template <class T>
T MIN(T a, T b){return ((a<b)?a:b);}
template <class T>
T MOD(T a){return ((a>=0)?a:(-1*a));}
template <class T>
void SWAP(T &a,T &b){T temp=a;a=b;b=temp;}

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;//for multiset use less_equal above

inline int ex(int a, int b){
	if(b==0||a==1){return 1;}
	if(a==0||b==1){return a;}
	int tmp=ex(a,(b/2));
	if(b%2){return ((((tmp*tmp)%N)*a)%N);}
	else{return ((tmp*tmp)%N);}
}
inline int inv(int k){
	if(k==1){return 1;}
	else{return ex(k,N-2);}
}
/*****************default********************/
int solve()
{
	int n;cin>>n;
	string str;cin>>str;
	int pres=0,max=0;
	string fin="";
	for(auto it:str)
	{
		fin+='0';
		if(it=='('){++pres;}
		else{--pres;}
		max=MAX(max,pres);
	}
	int tar=max/2;
	stack<int> st;pres=0;
	map<int,std::vector<pii>> mp;
	for(int i=0;i<n;++i)
	{
		if(str[i]=='('){++pres;st.push(i);}
		else
		{
			mp[pres].pb({st.top(),i});
			st.pop();--pres;
		}
	}
	REP(i,tar+1,n)
	{
		for(auto it:mp[i])
		{
			fin[it.x]='1';fin[it.y]='1';
		}
	}
	cout<<fin;
}
signed main(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
	speed
	int tt=1;
	//cin>>tt;
	while(tt--)
	{
		solve();
	}
	return 0;
}


    #include<bits/stdc++.h>
    #define int            		long long
    #define x              		first
    #define y              		second
    #define REP(i,sss,eee) 		for(int i=sss;i<=eee;++i)
    #define pb             		push_back
    #define pii            		pair<int,int>
    #define speed          		ios_base::sync_with_stdio(0);cin.tie(0);
    using namespace std;
    template <class T>
    T MAX(T a, T b){return ((a>b)?a:b);}
    int solve()
    {
    	int n;cin>>n;
    	string str;cin>>str;
    	int pres=0,max=0;
    	string fin="";
    	for(auto it:str)
    	{
    		fin+='0';
    		if(it=='('){++pres;}
    		else{--pres;}
    		max=MAX(max,pres);
    	}
    	int tar=max/2;
    	stack<int> st;pres=0;
    	map<int,std::vector<pii>> mp;
    	for(int i=0;i<n;++i)
    	{
    		if(str[i]=='('){++pres;st.push(i);}
    		else
    		{
    			mp[pres].pb({st.top(),i});
    			st.pop();--pres;
    		}
    	}
    	REP(i,tar+1,n)
    	{
    		for(auto it:mp[i])
    		{
    			fin[it.x]='1';fin[it.y]='1';
    		}
    	}
    	cout<<fin;
    }
    signed main(){
    	#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        #endif
    	speed
    	int tt=1;
    	//cin>>tt;
    	while(tt--)
    	{
    		solve();
    	}
    	return 0;
    }


    #include<bits/stdc++.h>
    #define mpa make_pair
    #define pb push_back
    using namespace std;

    int main(){
        int n;
        cin >> n;
        string s;
        cin >> s;
        int dep = 0;
        int mdep = 0;
        stack<int>stk;

        string res = "";

        //map< int,vector < pair<int,int> > >mp;
        vector< vector<pair<int,int> > >mp;
        mp.resize(n+1);
        for(int i=0 ; i<n ; i++){
            res += '0';
            if(s[i] == '('){
                stk.push(i);
                dep++;
            }
            else{
                mp[dep].pb({stk.top(),i});
                dep--;
                stk.pop();
            }
            mdep = max(mdep,dep);
        }

        //cout << "#";
        int tar = mdep/2;

        for (int i=tar+1 ; i<n ; i++){
            int len = mp[i].size();
            for(int j=0 ; j<len ; j++){
                res[mp[i][j].first] = '1';
                res[mp[i][j].second] = '1';
            }
        }
        cout << res << "\n";
        return 0;
    }


    #include<bits/stdc++.h>
    #define mpa make_pair
    #define pb push_back
    using namespace std;

    int main(){
        int n;
        cin >> n;
        string s;
        cin >> s;
        int dep = 0;
        int mdep = 0;
        stack<int>stk;

        string res = "";

        //map< int,vector < pair<int,int> > >mp;
        vector< vector<pair<int,int> > >mp;
        mp.resize(n+1);
        for(int i=0 ; i<n ; i++){
            res += "0";
            if(s[i] == '('){
                stk.push(i);
                dep++;
            }
            else{
                mp[dep].pb(mpa(stk.top(),i));
                dep--;
                stk.pop();
            }
            mdep = max(mdep,dep);
        }

        //cout << "#";
        int tar = mdep/2;

        for (int i=tar+1 ; i<n ; i++){
            int len = mp[i].size();
            for(int j=0 ; j<len ; j++){
                res[mp[i][j].first] = '1';
                res[mp[i][j].second] = '1';
            }
        }
        cout << res << "\n";
        return 0;
    }


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

    int main(){
    	#ifndef ONLINE_JUDGE
    	freopen("input.txt","r",stdin);
    	freopen("output.txt","w",stdout);
    	#endif
    	ios_base::sync_with_stdio(0);cin.tie(0);
        int n;
        cin >> n;
        string s;
        cin >> s;
        int dep = 0;
        int mdep = 0;
        stack<int>stk;

        string res = "";

        //map< int,vector < pair<int,int> > >mp;
        vector< vector<pair<int,int> > >mp;
        mp.resize(n+1);
        for(int i=0 ; i<n ; i++){
            res = res + "0";
            if(s[i] == '('){
                stk.push(i);
                dep++;
            }
            else{
                mp[dep].pb({stk.top(),i});
                dep--;
                stk.pop();
            }
            mdep = max(mdep,dep);
        }

        //cout << "#";
        int tar = mdep/2;

        for (int i=tar+1 ; i<n ; i++){
            int len = mp[i].size();
            for(int j=0 ; j<len ; j++){
                res[mp[i][j].first] = '1';
                res[mp[i][j].second] = '1';
            }
        }
        cout << res << "\n";
        return 0;
    }


#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch BicoloredRBS | diff BicoloredRBS.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address BicoloredRBS.cpp && ./a.out

/*

 5/15/2019

 8:09-8:34 WA

 */

const int MAX_N=1e6+1;
int N;
string S;

int dep(string &S) {
  int N=SZ(S);
  int d=0,res=0;
  REP(i,N) {
    if(S[i]=='(') ++d;
    else --d;
        if(d<0) dump(S);
    assert(d>=0);
    SMAX(res,d);
  }
  assert(d==0);
  return res;
}
int res[MAX_N];
bool ok(int D) {
  int d=0; bool reached=false;
  ZERO(res);
  string T;
  REP(i,N) {
    if(!reached) {
      if(S[i]=='(') {
        ++d;
        if(d==D+1) {
          reached=true;
          T.push_back(S[i]);
          res[i]=1;
          --d;
        }
      } else {
        --d;
      }
    } else {
      if(d>0&&S[i]==')') --d;
      else {
        T.push_back(S[i]);
        res[i]=1;
      }
    }
  }
  if(!reached) return true;
//  dump(D,T);
  return (dep(T)<=D);
}
void solve() {
  int good=1e7,bad=0;
  while(abs(good-bad)>1) {
    int m=(good+bad)/2;
    bool a=ok(m);
    (a?good:bad)=m;
  }
//  dump(good);
  assert(ok(good));
  REP(i,N) printf("%d",res[i]);
  println("");

  vector<string> X(2);
  REP(i,N) X[res[i]].push_back(S[i]);
  int d1=dep(X[0]),d2=dep(X[1]);
  assert(max(d1,d2)==good);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

  cin>>N>>S;
  solve();

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch BicoloredRBS | diff BicoloredRBS.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address BicoloredRBS.cpp && ./a.out

/*

 5/15/2019

 8:09-8:34 WA

 */

const int MAX_N=1e6+1;
int N;
string S;

int dep(string &S) {
  int N=SZ(S);
  int d=0,res=0;
  REP(i,N) {
    if(S[i]=='(') ++d;
    else --d;
        if(d<0) dump(S);
    assert(d>=0);
    SMAX(res,d);
  }
  assert(d==0);
  return res;
}
int res[MAX_N];
bool ok(int D) {
  int d=0; bool reached=false;
  ZERO(res);
  string T;
  REP(i,N) {
    if(!reached) {
      if(S[i]=='(') {
        ++d;
        if(d==D) reached=true;
      } else {
        --d;
      }
    } else {
      if(d>0&&S[i]==')') --d;
      else {
        T.push_back(S[i]);
        res[i]=1;
      }
    }
  }
  if(!reached) return true;
//  dump(D,T);
  return (dep(T)<=D);
}
void solve() {
  int good=1e7,bad=0;
  while(abs(good-bad)>1) {
    int m=(good+bad)/2;
    bool a=ok(m);
    (a?good:bad)=m;
  }
//  dump(good);
  ok(good);
  REP(i,N) printf("%d",res[i]);
  println("");

  vector<string> X(2);
  REP(i,N) X[res[i]].push_back(S[i]);
  int d1=dep(X[0]),d2=dep(X[1]);
  assert(max(d1,d2)==good);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

  cin>>N>>S;
  solve();

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch BicoloredRBS | diff BicoloredRBS.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address BicoloredRBS.cpp && ./a.out

/*

 5/15/2019

 8:09-8:34 WA
 9:18 AC

 I quickly figured out that greedy works though, my wrong solution was not considering a case such that there are multiple positions with maximum depth 😞

 https://codeforces.com/blog/entry/67058
 https://cinnamo-coder.hatenablog.com/entry/2019/05/16/132831

 It's nice to construct by parity

 */

const int MAX_N=1e6+1;
int N;
string S;
int res[MAX_N];

void solve() {
  int bal=0;
  REP(i,N) {
    if(S[i]=='(') {
      ++bal;
      res[i]=bal%2;
    } else {
      res[i]=bal%2;
      --bal;
    }
  }
  REP(i,N) printf("%d",res[i]);
  println("");
}

int dep(string &S) {
  int N=SZ(S);
  int d=0,res=0;
  REP(i,N) {
    if(S[i]=='(') ++d;
    else --d;
//        if(d<0) dump(S);
    assert(d>=0);
    SMAX(res,d);
  }
  assert(d==0);
  return res;
}

void solve_org() {
  int d=0,maxd=dep(S),D=(maxd+1)/2;
//  dump(maxd,D);
  REP(i,N) {
    if(d<D&&S[i]=='(') ++d;
    else if(d>0&&d<=D&&S[i]==')') --d;
    else res[i]=1;
  }
  REP(i,N) printf("%d",res[i]);
  println("");

  vector<string> X(2);
  REP(i,N) X[res[i]].push_back(S[i]);
  int d1=dep(X[0]),d2=dep(X[1]);
//  dump(d1,d2);
  assert(max(d1,d2)==D);
}

bool ok(int D) {
  int d=0; bool reached=false;
  ZERO(res);
  string T;
  REP(i,N) {
    if(!reached) {
      if(S[i]=='(') {
        ++d;
        if(d==D+1) {
          reached=true;
          T.push_back(S[i]);
          res[i]=1;
          --d;
        }
      } else {
        --d;
      }
    } else {
      if(d>0&&S[i]==')') --d;
      else {
        T.push_back(S[i]);
        res[i]=1;
      }
    }
  }
  if(!reached) return true;
//  dump(D,T);
  return (dep(T)<=D);
}
void solve_wrong() {
  int good=1e7,bad=0;
  while(abs(good-bad)>1) {
    int m=(good+bad)/2;
    bool a=ok(m);
    (a?good:bad)=m;
  }
//  dump(good);
  assert(ok(good));
  REP(i,N) printf("%d",res[i]);
  println("");

  vector<string> X(2);
  REP(i,N) X[res[i]].push_back(S[i]);
  int d1=dep(X[0]),d2=dep(X[1]);
  assert(max(d1,d2)==good);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

  cin>>N>>S;
  solve();

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch BicoloredRBS | diff BicoloredRBS.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address BicoloredRBS.cpp && ./a.out

/*

 5/15/2019

 8:09-8:34 WA
 9:00 give up

 */

const int MAX_N=1e6+1;
int N;
string S;
int res[MAX_N];

int dep(string &S) {
  int N=SZ(S);
  int d=0,res=0;
  REP(i,N) {
    if(S[i]=='(') ++d;
    else --d;
        if(d<0) dump(S);
    assert(d>=0);
    SMAX(res,d);
  }
  assert(d==0);
  return res;
}

void solve() {
  int d=0,maxd=dep(S),D=(maxd+1)/2;
  bool reached=false;
  REP(i,N) {
    if(!reached) {
      if(S[i]=='(') {
        ++d;
        if(d==D) {
          reached=true;
        }
      } else {
        --d;
      }
    } else {
      if(d>0&&S[i]==')') --d;
      else {
        res[i]=1;
      }
    }
  }
  REP(i,N) printf("%d",res[i]);
  println("");

  vector<string> X(2);
  REP(i,N) X[res[i]].push_back(S[i]);
  int d1=dep(X[0]),d2=dep(X[1]);
  assert(max(d1,d2)==D);
}

bool ok(int D) {
  int d=0; bool reached=false;
  ZERO(res);
  string T;
  REP(i,N) {
    if(!reached) {
      if(S[i]=='(') {
        ++d;
        if(d==D+1) {
          reached=true;
          T.push_back(S[i]);
          res[i]=1;
          --d;
        }
      } else {
        --d;
      }
    } else {
      if(d>0&&S[i]==')') --d;
      else {
        T.push_back(S[i]);
        res[i]=1;
      }
    }
  }
  if(!reached) return true;
//  dump(D,T);
  return (dep(T)<=D);
}
void solve_wrong() {
  int good=1e7,bad=0;
  while(abs(good-bad)>1) {
    int m=(good+bad)/2;
    bool a=ok(m);
    (a?good:bad)=m;
  }
//  dump(good);
  assert(ok(good));
  REP(i,N) printf("%d",res[i]);
  println("");

  vector<string> X(2);
  REP(i,N) X[res[i]].push_back(S[i]);
  int d1=dep(X[0]),d2=dep(X[1]);
  assert(max(d1,d2)==good);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

  cin>>N>>S;
  solve();

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch BicoloredRBS | diff BicoloredRBS.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address BicoloredRBS.cpp && ./a.out

/*

 5/15/2019

 8:09-8:34 WA
 9:00 give up

 */

const int MAX_N=1e6+1;
int N;
string S;
int res[MAX_N];

int dep(string &S) {
  int N=SZ(S);
  int d=0,res=0;
  REP(i,N) {
    if(S[i]=='(') ++d;
    else --d;
        if(d<0) dump(S);
    assert(d>=0);
    SMAX(res,d);
  }
  assert(d==0);
  return res;
}

void solve() {
  int d=0,maxd=dep(S),D=(maxd+1)/2;
//  dump(maxd,D);
  REP(i,N) {
    if(d<D&&S[i]=='(') ++d;
    else if(d>0&&d<=D&&S[i]==')') --d;
    else res[i]=1;
  }
  REP(i,N) printf("%d",res[i]);
  println("");

  vector<string> X(2);
  REP(i,N) X[res[i]].push_back(S[i]);
  int d1=dep(X[0]),d2=dep(X[1]);
//  dump(d1,d2);
  assert(max(d1,d2)==D);
}

bool ok(int D) {
  int d=0; bool reached=false;
  ZERO(res);
  string T;
  REP(i,N) {
    if(!reached) {
      if(S[i]=='(') {
        ++d;
        if(d==D+1) {
          reached=true;
          T.push_back(S[i]);
          res[i]=1;
          --d;
        }
      } else {
        --d;
      }
    } else {
      if(d>0&&S[i]==')') --d;
      else {
        T.push_back(S[i]);
        res[i]=1;
      }
    }
  }
  if(!reached) return true;
//  dump(D,T);
  return (dep(T)<=D);
}
void solve_wrong() {
  int good=1e7,bad=0;
  while(abs(good-bad)>1) {
    int m=(good+bad)/2;
    bool a=ok(m);
    (a?good:bad)=m;
  }
//  dump(good);
  assert(ok(good));
  REP(i,N) printf("%d",res[i]);
  println("");

  vector<string> X(2);
  REP(i,N) X[res[i]].push_back(S[i]);
  int d1=dep(X[0]),d2=dep(X[1]);
  assert(max(d1,d2)==good);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

  cin>>N>>S;
  solve();

  return 0;
}