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

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef gp_hash_table<int, null_type,hash<int>, equal_to<int>, direct_mask_range_hashing<int>, linear_probe_fn<>,
    hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>,true>> hash_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-9
#define MOD 1000000007
#define MOD2 1494318097
#define SEED 131
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 100005
#define MAXD 15

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

const ld PI = (ld)4*atanl(1);

mt19937 g1(chrono::steady_clock::now().time_since_epoch().count());

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

struct node{
    int l,r;
    int map[MAXD];
    ll sum[MAXD];
    inline void make_iden(){
        for(int i=0; i<10; i++)
            map[i] = i;
    }
    inline void clear(){
        ll tmp[MAXD];
        memset(tmp,0,sizeof tmp);
        for(int i=0; i<10; i++)
            tmp[map[i]]+=sum[i];
        for(int i=0; i<10; i++)
            sum[i] = tmp[i];
        make_iden();
    }
    inline void merge(node par){
        ll tmp[MAXD];
        memset(tmp,0,sizeof tmp);
        for(int i=0; i<10; i++){
            map[i] = par.map[map[i]];
            tmp[map[i]]+=sum[i];
        }
        for(int i=0; i<10; i++)
            sum[i] = tmp[i];
    }
};

int len,num_q,lim[MAXN],nums[MAXN][MAXD];
node seg[4*MAXN];

inline void push_up(int rt){
    memset(seg[rt].sum,0,sizeof seg[rt].sum);
    for(int i=0; i<10; i++){
        seg[rt].sum[seg[rt<<1].map[i]]+=seg[rt<<1].sum[i];
        seg[rt].sum[seg[rt<<1|1].map[i]]+=seg[rt<<1|1].sum[i];
    }
}

inline void push_down(int rt){
    if(seg[rt].l != seg[rt].r){
        seg[rt<<1].merge(seg[rt]);
        seg[rt<<1|1].merge(seg[rt]);
    }
    seg[rt].clear();
}

void build(int l, int r, int rt){
    seg[rt].l = l, seg[rt].r = r;
    seg[rt].make_iden();
    if(l == r){
        ll s = 1;
        for(int i=0; i<lim[l]; i++){
            seg[rt].sum[nums[l][i]]+=s;
            s*=10;
        }
        return;
    }
    int mid = (l+r)/2;
    build(l,mid,rt<<1);
    build(mid+1,r,rt<<1|1);
    push_up(rt);
}

void update(int l, int r, int x, int y, int rt){
    push_down(rt);
    if(seg[rt].l == l && seg[rt].r == r){
        seg[rt].map[x] = y;
        return;
    }
    int mid = (seg[rt].l+seg[rt].r)/2;
    if(r <= mid) update(l,r,x,y,rt<<1);
    else if(l > mid) update(l,r,x,y,rt<<1|1);
    else update(l,mid,x,y,rt<<1), update(mid+1,r,x,y,rt<<1|1);
    push_up(rt);
}

ll query(int l, int r, int rt){
    push_down(rt);
    if(seg[rt].l == l && seg[rt].r == r){
        ll ret = 0;
        for(int i=0; i<10; i++)
            ret+=seg[rt].sum[i]*i;
        return ret;
    }
    int mid = (seg[rt].l+seg[rt].r)/2;
    if(r <= mid) return query(l,r,rt<<1);
    else if(l > mid) return query(l,r,rt<<1|1);
    return query(l,mid,rt<<1)+query(mid+1,r,rt<<1|1);
}

int main(){
    scanf("%d %d",&len,&num_q);
    for(int i=1; i<=len; i++){
        int a; scanf(" %d",&a);
        for(int k=0; k<=11; k++){
            if(a == 0){
                lim[i] = k;
                break;
            }
            nums[i][k] = a%10;
            a/=10;
        }
    }
    build(1,len,1);
    while(num_q--){
        int op,l,r; scanf(" %d %d %d",&op,&l,&r);
        if(op == 1){
            int x,y; scanf(" %d %d",&x,&y);
            update(l,r,x,y,1);
        }else printf("%lld\n",query(l,r,1));
    }
}


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

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef gp_hash_table<int, null_type,hash<int>, equal_to<int>, direct_mask_range_hashing<int>, linear_probe_fn<>,
    hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>,true>> hash_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-9
#define MOD 1000000007
#define MOD2 1494318097
#define SEED 131
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 100005
#define MAXD 15

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

const ld PI = (ld)4*atanl(1);

mt19937 g1(chrono::steady_clock::now().time_since_epoch().count());

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

struct node{
    int l,r;
    int map[MAXD];
    ll sum[MAXD];
    inline void make_iden(){
        for(int i=0; i<10; i++)
            map[i] = i;
    }
    inline void clear(){
        ll tmp[MAXD];
        memset(tmp,0,sizeof tmp);
        for(int i=0; i<10; i++)
            tmp[map[i]]+=sum[i];
        for(int i=0; i<10; i++)
            sum[i] = tmp[i];
        make_iden();
    }
    inline void merge(node par){
        ll tmp[MAXD];
        memset(tmp,0,sizeof tmp);
        for(int i=0; i<10; i++)
            map[i] = par.map[map[i]];
    }
};

int len,num_q,lim[MAXN],nums[MAXN][MAXD];
node seg[4*MAXN];

inline void push_up(int rt){
    memset(seg[rt].sum,0,sizeof seg[rt].sum);
    for(int i=0; i<10; i++){
        seg[rt].sum[seg[rt<<1].map[i]]+=seg[rt<<1].sum[i];
        seg[rt].sum[seg[rt<<1|1].map[i]]+=seg[rt<<1|1].sum[i];
    }
}

inline void push_down(int rt){
    if(seg[rt].l != seg[rt].r){
        seg[rt<<1].merge(seg[rt]);
        seg[rt<<1|1].merge(seg[rt]);
    }
    seg[rt].clear();
}

void build(int l, int r, int rt){
    seg[rt].l = l, seg[rt].r = r;
    seg[rt].make_iden();
    if(l == r){
        ll s = 1;
        for(int i=0; i<lim[l]; i++){
            seg[rt].sum[nums[l][i]]+=s;
            s*=10;
        }
        return;
    }
    int mid = (l+r)/2;
    build(l,mid,rt<<1);
    build(mid+1,r,rt<<1|1);
    push_up(rt);
}

void update(int l, int r, int x, int y, int rt){
    push_down(rt);
    if(seg[rt].l == l && seg[rt].r == r){
        seg[rt].map[x] = y;
        return;
    }
    int mid = (seg[rt].l+seg[rt].r)/2;
    if(r <= mid) update(l,r,x,y,rt<<1);
    else if(l > mid) update(l,r,x,y,rt<<1|1);
    else update(l,mid,x,y,rt<<1), update(mid+1,r,x,y,rt<<1|1);
    push_up(rt);
}

ll query(int l, int r, int rt){
    push_down(rt);
    if(seg[rt].l == l && seg[rt].r == r){
        ll ret = 0;
        for(int i=0; i<10; i++)
            ret+=seg[rt].sum[i]*i;
        return ret;
    }
    int mid = (seg[rt].l+seg[rt].r)/2;
    if(r <= mid) return query(l,r,rt<<1);
    else if(l > mid) return query(l,r,rt<<1|1);
    return query(l,mid,rt<<1)+query(mid+1,r,rt<<1|1);
}

int main(){
    scanf("%d %d",&len,&num_q);
    for(int i=1; i<=len; i++){
        int a; scanf(" %d",&a);
        for(int k=0; k<=11; k++){
            if(a == 0){
                lim[i] = k;
                break;
            }
            nums[i][k] = a%10;
            a/=10;
        }
    }
    build(1,len,1);
    while(num_q--){
        int op,l,r; scanf(" %d %d %d",&op,&l,&r);
        if(op == 1){
            int x,y; scanf(" %d %d",&x,&y);
            update(l,r,x,y,1);
        }else printf("%lld\n",query(l,r,1));
    }
}


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

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef gp_hash_table<int, null_type,hash<int>, equal_to<int>, direct_mask_range_hashing<int>, linear_probe_fn<>,
    hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>,true>> hash_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-9
#define MOD 1000000007
#define MOD2 1494318097
#define SEED 131
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 100005
#define MAXD 15

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

const ld PI = (ld)4*atanl(1);

mt19937 g1(chrono::steady_clock::now().time_since_epoch().count());

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

struct node{
    int l,r;
    int map[MAXD];
    ll sum[MAXD];
    inline void make_iden(){
        for(int i=0; i<10; i++)
            map[i] = i;
    }
    inline void clear(){
        ll tmp[MAXD];
        memset(tmp,0,sizeof tmp);
        for(int i=0; i<10; i++)
            tmp[map[i]]+=sum[i];
        for(int i=0; i<10; i++)
            sum[i] = tmp[i];
        make_iden();
    }
    inline void merge(node par){
        ll tmp[MAXD];
        memset(tmp,0,sizeof tmp);
        for(int i=0; i<10; i++){
            map[i] = par.map[map[i]];
            tmp[map[i]]+=sum[i];
        }
        for(int i=0; i<10; i++)
            sum[i] = tmp[i];
    }
};

int len,num_q,lim[MAXN],nums[MAXN][MAXD];
node seg[4*MAXN];

inline void push_up(int rt){
    memset(seg[rt].sum,0,sizeof seg[rt].sum);
    for(int i=0; i<10; i++){
        seg[rt].sum[seg[rt<<1].map[i]]+=seg[rt<<1].sum[i];
        seg[rt].sum[seg[rt<<1|1].map[i]]+=seg[rt<<1|1].sum[i];
    }
}

inline void push_down(int rt){
    if(seg[rt].l == seg[rt].r) return;
    seg[rt<<1].merge(seg[rt]);
    seg[rt<<1|1].merge(seg[rt]);
    seg[rt].clear();
}

void build(int l, int r, int rt){
    seg[rt].l = l, seg[rt].r = r;
    seg[rt].make_iden();
    if(l == r){
        ll s = 1;
        for(int i=0; i<lim[l]; i++){
            seg[rt].sum[nums[l][i]]+=s;
            s*=10;
        }
        return;
    }
    int mid = (l+r)/2;
    build(l,mid,rt<<1);
    build(mid+1,r,rt<<1|1);
    push_up(rt);
}

void update(int l, int r, int x, int y, int rt){
    push_down(rt);
    if(seg[rt].l == l && seg[rt].r == r){
        seg[rt].map[x] = y;
        return;
    }
    int mid = (seg[rt].l+seg[rt].r)/2;
    if(r <= mid) update(l,r,x,y,rt<<1);
    else if(l > mid) update(l,r,x,y,rt<<1|1);
    else update(l,mid,x,y,rt<<1), update(mid+1,r,x,y,rt<<1|1);
    push_up(rt);
}

ll query(int l, int r, int rt){
    push_down(rt);
    if(seg[rt].l == l && seg[rt].r == r){
        ll ret = 0;
        for(int i=0; i<10; i++)
            ret+=seg[rt].sum[i]*i;
        return ret;
    }
    int mid = (seg[rt].l+seg[rt].r)/2;
    if(r <= mid) return query(l,r,rt<<1);
    else if(l > mid) return query(l,r,rt<<1|1);
    return query(l,mid,rt<<1)+query(mid+1,r,rt<<1|1);
}

int main(){
    scanf("%d %d",&len,&num_q);
    for(int i=1; i<=len; i++){
        int a; scanf(" %d",&a);
        for(int k=0; k<=11; k++){
            if(a == 0){
                lim[i] = k;
                break;
            }
            nums[i][k] = a%10;
            a/=10;
        }
        assert(lim[i]);
    }
    build(1,len,1);
    while(num_q--){
        int op,l,r; scanf(" %d %d %d",&op,&l,&r);
        if(op == 1){
            int x,y; scanf(" %d %d",&x,&y);
            update(l,r,x,y,1);
        }else printf("%lld\n",query(l,r,1));
    }
}


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

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef gp_hash_table<int, null_type,hash<int>, equal_to<int>, direct_mask_range_hashing<int>, linear_probe_fn<>,
    hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>,true>> hash_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-9
#define MOD 1000000007
#define MOD2 1494318097
#define SEED 131
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 100005
#define MAXD 15

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

const ld PI = (ld)4*atanl(1);

mt19937 g1(chrono::steady_clock::now().time_since_epoch().count());

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

struct node{
    int l,r;
    int map[MAXD];
    ll sum[MAXD];
    inline void make_iden(){
        for(int i=0; i<10; i++)
            map[i] = i;
    }
    inline void clear(){
        ll tmp[MAXD]; memset(tmp,0,sizeof tmp);
        for(int i=0; i<10; i++)
            tmp[map[i]]+=sum[i];
        for(int i=0; i<10; i++)
            sum[i] = tmp[i];
        make_iden();
    }
    inline void merge(node par){
        ll tmp[MAXD]; memset(tmp,0,sizeof tmp);
        for(int i=0; i<10; i++){
            map[i] = par.map[map[i]];
            tmp[map[i]]+=sum[i];
        }
        for(int i=0; i<10; i++)
            sum[i] = tmp[i];
    }
};

int len,num_q,lim[MAXN],nums[MAXN][MAXD];
node seg[4*MAXN];

inline void push_up(int rt){
    memset(seg[rt].sum,0,sizeof seg[rt].sum);
    for(int i=0; i<10; i++){
        seg[rt].sum[seg[rt<<1].map[i]]+=seg[rt<<1].sum[i];
        seg[rt].sum[seg[rt<<1|1].map[i]]+=seg[rt<<1|1].sum[i];
    }
}

inline void push_down(int rt){
    seg[rt<<1].merge(seg[rt]);
    seg[rt<<1|1].merge(seg[rt]);
    seg[rt].clear();
}

void build(int l, int r, int rt){
    seg[rt].l = l, seg[rt].r = r;
    seg[rt].make_iden();
    if(l == r){
        ll s = 1;
        for(int i=0; i<lim[l]; i++){
            seg[rt].sum[nums[l][i]]+=s;
            s*=10;
        }
        return;
    }
    int mid = (l+r)/2;
    build(l,mid,rt<<1);
    build(mid+1,r,rt<<1|1);
    push_up(rt);
}

void update(int l, int r, int x, int y, int rt){
    push_down(rt);
    if(seg[rt].l == l && seg[rt].r == r){
        seg[rt].map[x] = y;
        return;
    }
    int mid = (seg[rt].l+seg[rt].r)/2;
    if(r <= mid) update(l,r,x,y,rt<<1);
    else if(l > mid) update(l,r,x,y,rt<<1|1);
    else update(l,mid,x,y,rt<<1), update(mid+1,r,x,y,rt<<1|1);
    push_up(rt);
}

ll query(int l, int r, int rt){
    push_down(rt);
    if(seg[rt].l == l && seg[rt].r == r){
        ll ret = 0;
        for(int i=0; i<10; i++)
            ret+=seg[rt].sum[i]*i;
        return ret;
    }
    int mid = (seg[rt].l+seg[rt].r)/2;
    if(r <= mid) return query(l,r,rt<<1);
    else if(l > mid) return query(l,r,rt<<1|1);
    return query(l,mid,rt<<1)+query(mid+1,r,rt<<1|1);
}

int main(){
    scanf("%d %d",&len,&num_q);
    for(int i=1; i<=len; i++){
        int a; scanf(" %d",&a);
        for(int k=0; k<=11; k++){
            if(a == 0){
                lim[i] = k;
                break;
            }
            nums[i][k] = a%10;
            a/=10;
        }
    }
    build(1,len,1);
    while(num_q--){
        int op,l,r; scanf(" %d %d %d",&op,&l,&r);
        if(op == 1){
            int x,y; scanf(" %d %d",&x,&y);
            update(l,r,x,y,1);
        }else printf("%lld\n",query(l,r,1));
    }
}


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

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef gp_hash_table<int, null_type,hash<int>, equal_to<int>, direct_mask_range_hashing<int>, linear_probe_fn<>,
    hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>,true>> hash_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-9
#define MOD 1000000007
#define MOD2 1494318097
#define SEED 131
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 100005
#define MAXD 15

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

const ld PI = (ld)4*atanl(1);

mt19937 g1(chrono::steady_clock::now().time_since_epoch().count());

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

struct node{
    int l,r;
    int map[MAXD];
    ll sum[MAXD];
    inline void make_iden(){
        for(int i=0; i<10; i++)
            map[i] = i;
    }
    inline void clear(){
        ll tmp[MAXD]; memset(tmp,0,sizeof tmp);
        for(int i=0; i<10; i++)
            tmp[map[i]]+=sum[i];
        for(int i=0; i<10; i++)
            sum[i] = tmp[i];
        make_iden();
    }
    inline void merge(node par){
        ll tmp[MAXD]; memset(tmp,0,sizeof tmp);
        for(int i=0; i<10; i++){
            map[i] = par.map[map[i]];
            tmp[map[i]]+=sum[i];
        }
        for(int i=0; i<10; i++)
            sum[i] = tmp[i];
    }
};

int len,num_q,lim[MAXN],nums[MAXN][MAXD];
node seg[4*MAXN];

inline void push_up(int rt){
    memset(seg[rt].sum,0,sizeof seg[rt].sum);
    for(int i=0; i<10; i++){
        seg[rt].sum[seg[rt<<1].map[i]]+=seg[rt<<1].sum[i];
        seg[rt].sum[seg[rt<<1|1].map[i]]+=seg[rt<<1|1].sum[i];
    }
}

inline void push_down(int rt){
    if(seg[rt].l == seg[rt].r) return;
    seg[rt<<1].merge(seg[rt]);
    seg[rt<<1|1].merge(seg[rt]);
    seg[rt].clear();
}

void build(int l, int r, int rt){
    seg[rt].l = l, seg[rt].r = r;
    seg[rt].make_iden();
    if(l == r){
        ll s = 1;
        for(int i=0; i<lim[l]; i++){
            seg[rt].sum[nums[l][i]]+=s;
            s*=10;
        }
        return;
    }
    int mid = (l+r)/2;
    build(l,mid,rt<<1);
    build(mid+1,r,rt<<1|1);
    push_up(rt);
}

void update(int l, int r, int x, int y, int rt){
    push_down(rt);
    if(seg[rt].l == l && seg[rt].r == r){
        seg[rt].map[x] = y;
        return;
    }
    int mid = (seg[rt].l+seg[rt].r)/2;
    if(r <= mid) update(l,r,x,y,rt<<1);
    else if(l > mid) update(l,r,x,y,rt<<1|1);
    else update(l,mid,x,y,rt<<1), update(mid+1,r,x,y,rt<<1|1);
    push_up(rt);
}

ll query(int l, int r, int rt){
    push_down(rt);
    if(seg[rt].l == l && seg[rt].r == r){
        ll ret = 0;
        for(int i=0; i<10; i++)
            ret+=seg[rt].sum[i]*i;
        return ret;
    }
    int mid = (seg[rt].l+seg[rt].r)/2;
    if(r <= mid) return query(l,r,rt<<1);
    else if(l > mid) return query(l,r,rt<<1|1);
    return query(l,mid,rt<<1)+query(mid+1,r,rt<<1|1);
}

int main(){
    scanf("%d %d",&len,&num_q);
    for(int i=1; i<=len; i++){
        int a; scanf(" %d",&a);
        for(int k=0; k<=11; k++){
            if(a == 0){
                lim[i] = k;
                break;
            }
            nums[i][k] = a%10;
            a/=10;
        }
    }
    build(1,len,1);
    while(num_q--){
        int op,l,r; scanf(" %d %d %d",&op,&l,&r);
        if(op == 1){
            int x,y; scanf(" %d %d",&x,&y);
            update(l,r,x,y,1);
        }else printf("%lld\n",query(l,r,1));
    }
}


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

typedef long long ll;
const int N = 1e5 + 100, K = 11;

ll n, q, form, l, r, x, y, a[N], pow_10[K];
struct node {
	ll cnt[K], lazy[K], sum;
} seg[N << 2];

int digit(int a, int dex) {
	return (a / pow_10[dex]) % 10;
}

void merge(int v, int lc, int rc) {
	for (int i = 0; i < K; i++)
		seg[v].cnt[i] = seg[lc].cnt[i] + seg[rc].cnt[i];
	for (int i = 0; i < K; i++)
		seg[v].lazy[i] = i;
	seg[v].sum = seg[lc].sum + seg[rc].sum;
}

void build(int v = 1, int s = 0, int e = n) {
	if(e - s == 1) {
		for (int i = 0; pow_10[i] <= a[s]; i++)
			seg[v].cnt[digit(a[s], i)] += pow_10[i];
		for (int i = 0; i < K; i++)
			seg[v].lazy[i] = i;
		seg[v].sum = a[s];
		return;
	}
	int mid = (s + e) >> 1, lc = v << 1, rc = lc + 1;
	build(lc, s, mid);
	build(rc, mid, e);
	merge(v, lc, rc);
}

void update(int v, int u) {
	ll help[K] = {};
	for (int i = 0; i < K; i++) {
		seg[u].sum += (seg[v].lazy[i] - i) * seg[u].cnt[i];
		help[seg[v].lazy[i]] += seg[u].cnt[i];
	}
	for (int i = 0; i < K; i++)
		seg[u].cnt[i] = help[i];
	for (int i = 0; i < K; i++)
		seg[u].lazy[i] = seg[v].lazy[seg[u].lazy[i]];
}

void update_child(int v, int lc, int rc) {
	update(v, lc);
	update(v, rc);
	for (int i = 0; i < K; i++)
		seg[v].lazy[i] = i;
}

void change(int l, int r, int x, int y, int v = 1, int s = 0, int e = n) {
	if(e <= l || r <= s)
		return;
	if(l <= s && e <= r) {
		for (int i = 0; i < K; i++)
			if(seg[v].lazy[i] == x)
				seg[v].lazy[i] = y;
		seg[v].sum += (y - x) * seg[v].cnt[x];
		seg[v].cnt[y] += seg[v].cnt[x];
		seg[v].cnt[x] = 0;
		return;
	}
	int mid = (s + e) >> 1, lc = v << 1, rc = lc + 1;
	update_child(v, lc, rc);
	change(l, r, x, y, lc, s, mid);
	change(l, r, x, y, rc, mid, e);
	merge(v, lc, rc);
}

ll get(int l, int r, int v = 1, int s = 0, int e = n) {
	if(e <= l || r <= s)
		return 0;
	if(l <= s && e <= r)
		return seg[v].sum;
	int mid = (s + e) >> 1, lc = v << 1, rc = lc + 1;
	update_child(v, lc, rc);
	//merge(v, lc, rc);
	return get(l, r, lc, s, mid) + get(l, r, rc, mid, e);
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	pow_10[0] = 1;
	for (int i = 1; i < K; i++)
		pow_10[i] = 10 * pow_10[i - 1];

	cin >> n >> q;
	for (int i = 0; i < n; i++)
		cin >> a[i];

	build();

	while(q--) {
		cin >> form >> l >> r;
		l--;
		if(form == 1) {
			cin >> x >> y;
			change(l, r, x, y);
		}
		else
			cout << get(l, r) << '\n';
	}
	return 0;
}


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

typedef long long ll;
const int N = 1e5 + 100, K = 11;

ll n, q, form, l, r, x, y, a[N], pow_10[K];
struct node {
	ll cnt[K], lazy[K], sum;
} seg[N << 2];

int digit(int a, int dex) {
	return (a / pow_10[dex]) % 10;
}

void merge(int v, int lc, int rc) {
	for (int i = 0; i < K; i++)
		seg[v].cnt[i] = seg[lc].cnt[i] + seg[rc].cnt[i];
	for (int i = 0; i < K; i++)
		seg[v].lazy[i] = i;
	seg[v].sum = seg[lc].sum + seg[rc].sum;
}

void build(int v = 1, int s = 0, int e = n) {
	for (int i = 0; i < K; i++)
		seg[v].lazy[i] = i;
	if(e - s == 1) {
		for (int i = 0; pow_10[i] <= a[s]; i++)
			seg[v].cnt[digit(a[s], i)] += pow_10[i];
		seg[v].sum = a[s];
		return;
	}
	int mid = (s + e) >> 1, lc = v << 1, rc = lc + 1;
	build(lc, s, mid);
	build(rc, mid, e);
	merge(v, lc, rc);
}

void update(int v, int u) {
	ll help[K];
	memset(help, 0, sizeof help);
	for (int i = 0; i < K; i++) {
		seg[u].sum += (seg[v].lazy[i] - i) * seg[u].cnt[i];
		help[seg[v].lazy[i]] += seg[u].cnt[i];
	}
	for (int i = 0; i < K; i++)
		seg[u].cnt[i] = help[i];
	for (int i = 0; i < K; i++)
		seg[u].lazy[i] = seg[v].lazy[seg[u].lazy[i]];
}

void update_child(int v, int lc, int rc) {
	update(v, lc);
	update(v, rc);
	for (int i = 0; i < K; i++)
		seg[v].lazy[i] = i;
}

void change(int l, int r, int x, int y, int v = 1, int s = 0, int e = n) {
	if(e <= l || r <= s)
		return;
	if(l <= s && e <= r) {
		for (int i = 0; i < K; i++)
			if(seg[v].lazy[i] == x)
				seg[v].lazy[i] = y;
		seg[v].sum += (y - x) * seg[v].cnt[x];
		seg[v].cnt[y] += seg[v].cnt[x];
		seg[v].cnt[x] = 0;
		return;
	}
	int mid = (s + e) >> 1, lc = v << 1, rc = lc + 1;
	update_child(v, lc, rc);
	change(l, r, x, y, lc, s, mid);
	change(l, r, x, y, rc, mid, e);
	merge(v, lc, rc);
}

ll get(int l, int r, int v = 1, int s = 0, int e = n) {
	if(e <= l || r <= s)
		return 0;
	if(l <= s && e <= r)
		return seg[v].sum;
	int mid = (s + e) >> 1, lc = v << 1, rc = lc + 1;
	update_child(v, lc, rc);
	ll res = get(l, r, lc, s, mid) + get(l, r, rc, mid, e);
	merge(v, lc, rc);
	return res;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	pow_10[0] = 1;
	for (int i = 1; i < K; i++)
		pow_10[i] = 10 * pow_10[i - 1];

	cin >> n >> q;
	for (int i = 0; i < n; i++)
		cin >> a[i];

	build();

	while(q--) {
		cin >> form >> l >> r;
		l--;
		if(form == 1) {
			cin >> x >> y;
			change(l, r, x, y);
		}
		else
			cout << get(l, r) << '\n';
	}
	return 0;
}


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

typedef long long ll;
const int N = 1e5 + 100, K = 11;

ll n, q, form, l, r, x, y, a[N], pow_10[K];
struct node {
	ll cnt[K], lazy[K];
} seg[N << 2];

int digit(int a, int dex) {
	return (a / pow_10[dex]) % 10;
}

void merge(int v, int lc, int rc) {
	for (int i = 0; i < K; i++)
		seg[v].cnt[i] = seg[lc].cnt[i] + seg[rc].cnt[i];
	for (int i = 0; i < K; i++)
		seg[v].lazy[i] = i;
}

void build(int v = 1, int s = 0, int e = n) {
	for (int i = 0; i < K; i++)
		seg[v].lazy[i] = i;
	if(e - s == 1) {
		for (int i = 0; pow_10[i] <= a[s]; i++)
			seg[v].cnt[digit(a[s], i)] += pow_10[i];
		return;
	}
	int mid = (s + e) >> 1, lc = v << 1, rc = lc + 1;
	build(lc, s, mid);
	build(rc, mid, e);
	merge(v, lc, rc);
}

void update(int v, int u) {
	ll help[K];
	memset(help, 0, sizeof help);
	for (int i = 0; i < K; i++)
		help[seg[v].lazy[i]] += seg[u].cnt[i];
	for (int i = 0; i < K; i++)
		seg[u].cnt[i] = help[i];
	for (int i = 0; i < K; i++)
		seg[u].lazy[i] = seg[v].lazy[seg[u].lazy[i]];
}

void update_child(int v, int lc, int rc) {
	update(v, lc);
	update(v, rc);
	for (int i = 0; i < K; i++)
		seg[v].lazy[i] = i;
}

void change(int l, int r, int x, int y, int v = 1, int s = 0, int e = n) {
	if(e <= l || r <= s)
		return;
	if(l <= s && e <= r) {
		for (int i = 0; i < K; i++)
			if(seg[v].lazy[i] == x)
				seg[v].lazy[i] = y;
		seg[v].cnt[y] += seg[v].cnt[x];
		seg[v].cnt[x] = 0;
		return;
	}
	int mid = (s + e) >> 1, lc = v << 1, rc = lc + 1;
	update_child(v, lc, rc);
	change(l, r, x, y, lc, s, mid);
	change(l, r, x, y, rc, mid, e);
	merge(v, lc, rc);
}

ll get(int l, int r, int v = 1, int s = 0, int e = n) {
	if(e <= l || r <= s)
		return 0;
	if(l <= s && e <= r) {
		ll res = 0;
		for (int i = 0; i < K; i++)
			res += i * seg[v].cnt[i];
		return res;
	}
	int mid = (s + e) >> 1, lc = v << 1, rc = lc + 1;
	update_child(v, lc, rc);
	return get(l, r, lc, s, mid) + get(l, r, rc, mid, e);
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	pow_10[0] = 1;
	for (int i = 1; i < K; i++)
		pow_10[i] = 10 * pow_10[i - 1];

	cin >> n >> q;
	for (int i = 0; i < n; i++)
		cin >> a[i];

	build();

	while(q--) {
		cin >> form >> l >> r;
		l--;
		if(form == 1) {
			cin >> x >> y;
			change(l, r, x, y);
		}
		else
			cout << get(l, r) << '\n';
	}
	return 0;
}


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

typedef long long ll;
const int N = 1e5 + 100, K = 11;

ll n, q, form, l, r, x, y, a[N], pow_10[K];
struct node {
	ll cnt[K], lazy[K], sum;
} seg[N << 2];

int digit(int a, int dex) {
	return (a / pow_10[dex]) % 10;
}

void merge(int v, int lc, int rc) {
	for (int i = 0; i < K; i++)
		seg[v].cnt[i] = seg[lc].cnt[i] + seg[rc].cnt[i];
	for (int i = 0; i < K; i++)
		seg[v].lazy[i] = i;
	seg[v].sum = seg[lc].sum + seg[rc].sum;
}

void build(int v = 1, int s = 0, int e = n) {
	for (int i = 0; i < K; i++)
		seg[v].lazy[i] = i;
	if(e - s == 1) {
		for (int i = 0; pow_10[i] <= a[s]; i++)
			seg[v].cnt[digit(a[s], i)] += pow_10[i];
		seg[v].sum = a[s];
		return;
	}
	int mid = (s + e) >> 1, lc = v << 1, rc = lc + 1;
	build(lc, s, mid);
	build(rc, mid, e);
	merge(v, lc, rc);
}

void update(int v, int u) {
	ll help[K];
	memset(help, 0, sizeof help);
	for (int i = 0; i < K; i++) {
		seg[u].sum += (seg[v].lazy[i] - i) * seg[u].cnt[i];
		help[seg[v].lazy[i]] += seg[u].cnt[i];
	}
	for (int i = 0; i < K; i++)
		seg[u].cnt[i] = help[i];
	for (int i = 0; i < K; i++)
		seg[u].lazy[i] = seg[v].lazy[seg[u].lazy[i]];
}

void update_child(int v, int lc, int rc) {
	update(v, lc);
	update(v, rc);
	for (int i = 0; i < K; i++)
		seg[v].lazy[i] = i;
}

void change(int l, int r, int x, int y, int v = 1, int s = 0, int e = n) {
	if(e <= l || r <= s)
		return;
	if(l <= s && e <= r) {
		for (int i = 0; i < K; i++)
			if(seg[v].lazy[i] == x)
				seg[v].lazy[i] = y;
		seg[v].sum += (y - x) * seg[v].cnt[x];
		seg[v].cnt[y] += seg[v].cnt[x];
		seg[v].cnt[x] = 0;
		return;
	}
	int mid = (s + e) >> 1, lc = v << 1, rc = lc + 1;
	update_child(v, lc, rc);
	change(l, r, x, y, lc, s, mid);
	change(l, r, x, y, rc, mid, e);
	merge(v, lc, rc);
}

ll get(int l, int r, int v = 1, int s = 0, int e = n) {
	if(e <= l || r <= s)
		return 0;
	if(l <= s && e <= r)
		return seg[v].sum;
	int mid = (s + e) >> 1, lc = v << 1, rc = lc + 1;
	update_child(v, lc, rc);
	return get(l, r, lc, s, mid) + get(l, r, rc, mid, e);
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	pow_10[0] = 1;
	for (int i = 1; i < K; i++)
		pow_10[i] = 10 * pow_10[i - 1];

	cin >> n >> q;
	for (int i = 0; i < n; i++)
		cin >> a[i];

	build();

	while(q--) {
		cin >> form >> l >> r;
		l--;
		if(form == 1) {
			cin >> x >> y;
			change(l, r, x, y);
		}
		else
			cout << get(l, r) << '\n';
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
#define MAX 200010
int a[MAX],b[MAX];
struct Node
{
	int x,y;
}c[MAX];
bool cmp(Node a,Node b)
{
	if(a.x==b.x)
	{
		return a.y<b.y;
	}
	return a.x<b.x;
}
int main()
{
	int n,k,K,ans,i,num,tires,w,flag,sum,flag2;
	while(scanf("%d%d",&n,&k)!=EOF)
	{
		memset(c,0,sizeof(c));
		memset(b,0,sizeof(b));
		ans = 0;num = 0;
		K=0;w=0;flag=0;flag2=0;
		scanf("%d",&a[0]);
		if(n==1 && a[0]>=0)
		{
			printf("0\n");
			continue;
		}
		if(a[0]>=0){flag = 1;b[K]++;flag2=1;}
		else{flag = -1;b[K]--;num++;}
		for(i=1;i<n;i++)
		{
			scanf("%d",&a[i]);
			if(a[i] >= 0 && flag == -1){flag = 1; K++;}
			else if(a[i] < 0 && flag == 1 && flag2!=1){flag = -1;c[w].x=b[K];c[w++].y=K; K++;}
			else if(a[i] < 0 && flag2==1){flag2=-1;b[K]=0;K=0;flag=-1;}
			if(a[i]>=0)
			{
				b[K]++;
			}
			else if(a[i]<0)
			{
				b[K]--;
			}
			if(a[i]<0)
			{
				num++;
			}
		}
		if(num>k)
		{
			printf("-1\n");
			continue;
		}
		sort(c,c+w,cmp);
		/*----
		for(i=0;i<w;i++)
		{
			printf("%d ",c[i].x);
		}
		puts("");
		for(i=0;i<w;i++)
		{
			printf("%d ",c[i].y);
		}
		puts("");
		*/
		sum=0;
		k-=num;
		for(i=0;i<w;i++)
		{
			if(c[i].x<=k)
			{
				b[c[i].y]=-1;
				k-=c[i].x;
			}
			else
			{
				break;
			}
		}
		//k-=sum;
		if(b[K]>0)
		{
			if(b[K]<=k)
			{
				b[K]=-1;
			}
			//c[w].x=b[K];
		//	c[w++].y=K;
		}
		/*----
		for(i=0;i<=K;i++)
		{
			printf("%d ",b[i]);
		}
		puts("");
		*/
		flag=0;tires = 0;
		for(i=0;i<=K;i++)
		{
			if(b[i]<0 && tires==0)
			{
				ans++;
				tires = 1;
			}
			else if(b[i]>=0 && tires==1)
			{
				ans++;
				tires = 0;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
#define MAX 200010
int a[MAX],b[MAX];
struct Node
{
	int x,y;
}c[MAX];
bool cmp(Node a,Node b)
{
	if(a.x==b.x)
	{
		return a.y<b.y;
	}
	return a.x<b.x;
}
int main()
{
	int n,k,K,ans,i,num,tires,w,flag,sum,flag2;
	while(scanf("%d%d",&n,&k)!=EOF)
	{
		memset(c,0,sizeof(c));
		memset(b,0,sizeof(b));
		ans = 0;num = 0;
		K=0;w=0;flag=0;flag2=0;
		scanf("%d",&a[0]);
		if(a[0]>=0){flag = 1;b[K]++;flag2=1;}
		else{flag = -1;b[K]--;num++;}
		for(i=1;i<n;i++)
		{
			scanf("%d",&a[i]);
			if(a[i] >= 0 && flag == -1){flag = 1; K++;}
			else if(a[i] < 0 && flag == 1 && flag2!=1){flag = -1;c[w].x=b[K];c[w++].y=K; K++;}
			else if(a[i] < 0 && flag2==1){flag2=-1;b[K]=0;K=0;flag=-1;}
			if(a[i]>=0)
			{
				b[K]++;
			}
			else if(a[i]<0)
			{
				b[K]--;
			}
			if(a[i]<0)
			{
				num++;
			}
		}
		if(K==0 && b[K]>=0)
		{
			printf("0\n");
			continue;
		}
		if(num>k)
		{
			printf("-1\n");
			continue;
		}
		sort(c,c+w,cmp);
		/*----
		for(i=0;i<w;i++)
		{
			printf("%d ",c[i].x);
		}
		puts("");
		for(i=0;i<w;i++)
		{
			printf("%d ",c[i].y);
		}
		puts("");
		*/
		sum=0;
		k-=num;
		for(i=0;i<w;i++)
		{
			if(c[i].x<=k)
			{
				b[c[i].y]=-1;
				k-=c[i].x;
			}
			else
			{
				break;
			}
		}
		//k-=sum;
		if(b[K]>0)
		{
			if(b[K]<=k)
			{
				b[K]=-1;
			}
			//c[w].x=b[K];
		//	c[w++].y=K;
		}
		/*----
		for(i=0;i<=K;i++)
		{
			printf("%d ",b[i]);
		}
		puts("");
		*/
		flag=0;tires = 0;
		for(i=0;i<=K;i++)
		{
			if(b[i]<0 && tires==0)
			{
				ans++;
				tires = 1;
			}
			else if(b[i]>=0 && tires==1)
			{
				ans++;
				tires = 0;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
#define MAX 200010
int a[MAX],b[MAX];
int main()
{
	int n,k,c,K,w,i,ans;
	while(scanf("%d%d",&n,&k)!=EOF)
	{
		K=0;
		for(i=0;i<n;i++)
		{
			scanf("%d",&c);
			if(c<0)
			{
				a[K++]=i;
			}
		}
		if(K>k)
		{
			printf("-1\n");
			continue;
		}
		if(K==0)
		{
			printf("0\n");
			continue;
		}
		w=0;
		for(i=1;i<K;i++)
		{
			b[w++]=a[i]-a[i-1]-1;
		}
		sort(b,b+w);
		k-=K;
		ans=2*K;
		for(i=0;i<w;i++)
		{
			if(k>=b[i])
			{
				k-=b[i];
				ans-=2;
			}
			else
			{
				break;
			}
		}
		if(n-a[K-1]-1<=k)
		{
			ans--;
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
#define MAX 200010
int a[MAX],b[MAX];
struct Node
{
	int x,y;
}c[MAX];
bool cmp(Node a,Node b)
{
	if(a.x==b.x)
	{
		return a.y<b.y;
	}
	return a.x<b.x;
}
int main()
{
	int n,k,K,ans,i,num,tires,w,flag,sum,flag2;
	while(scanf("%d%d",&n,&k)!=EOF)
	{
		memset(c,0,sizeof(c));
		memset(b,0,sizeof(b));
		ans = 0;num = 0;
		K=0;w=0;flag=0;flag2=0;
		scanf("%d",&a[0]);
		if(a[0]>=0){flag = 1;b[K]++;flag2=1;}
		else{flag = -1;b[K]--;num++;}
		for(i=1;i<n;i++)
		{
			scanf("%d",&a[i]);
			if(a[i] >= 0 && flag == -1){flag = 1; K++;}
			else if(a[i] < 0 && flag == 1 && flag2!=1){flag = -1;c[w].x=b[K];c[w++].y=K; K++;}
			else if(a[i] < 0 && flag2==1){flag2=-1;b[K]=0;K=0;flag=-1;}
			if(a[i]>=0)
			{
				b[K]++;
			}
			else if(a[i]<0)
			{
				b[K]--;
			}
			if(a[i]<0)
			{
				num++;
			}
		}
		if(num>k)
		{
			printf("-1\n");
			continue;
		}
		sort(c,c+w,cmp);
		/*----
		for(i=0;i<w;i++)
		{
			printf("%d ",c[i].x);
		}
		puts("");
		for(i=0;i<w;i++)
		{
			printf("%d ",c[i].y);
		}
		puts("");
		*/
		sum=0;
		k-=num;
		for(i=0;i<w;i++)
		{
			if(c[i].x<=k)
			{
				b[c[i].y]=-1;
				k-=c[i].x;
			}
			else
			{
				break;
			}
		}
		//k-=sum;
		if(b[K]>0)
		{
			if(b[K]<=k)
			{
				b[K]=-1;
			}
			//c[w].x=b[K];
		//	c[w++].y=K;
		}
		/*----
		for(i=0;i<=K;i++)
		{
			printf("%d ",b[i]);
		}
		puts("");
		*/
		flag=0;tires = 0;
		for(i=0;i<=K;i++)
		{
			if(b[i]<0 && tires==0)
			{
				ans++;
				tires = 1;
			}
			else if(b[i]>=0 && tires==1)
			{
				ans++;
				tires = 0;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
#define MAX 200010
int a[MAX],b[MAX];
struct Node
{
	int x,y;
}c[MAX];
bool cmp(Node a,Node b)
{
	return a.x<b.x;
}
int main()
{
	int n,k,K,ans,i,num,tires,w,flag,sum;
	while(scanf("%d%d",&n,&k)!=EOF)
	{
		memset(c,0,sizeof(c));
		memset(b,0,sizeof(b));
		ans = 0;num = 0;
		K=0;w=0;flag=0;
		scanf("%d",&a[0]);
		if(a[0]>=0){flag = 1;b[K]++;}
		else{flag = -1;b[K]--;num++;}
		for(i=1;i<n;i++)
		{
			scanf("%d",&a[i]);
			if(a[i] >= 0 && flag == -1){flag = 1; K++;}
			else if(a[i] < 0 && flag == 1){flag = -1;c[w].x=b[K];c[w++].y=K; K++;}
			if(a[i]>=0)
			{
				b[K]++;
			}
			else if(a[i]<0)
			{
				b[K]--;
			}
			if(a[i]<0)
			{
				num++;
			}
		}
		if(b[K]>0)
		{
			c[w].x=b[K];
			c[w++].y=K;
		}
		if(num>k)
		{
			printf("-1\n");
			continue;
		}
		sort(c,c+w,cmp);
		/*----
		for(i=0;i<w;i++)
		{
			printf("%d ",c[i]);
		}
		puts("");
		*/
		sum=0;
		k-=num;
		for(i=0;i<w;i++)
		{
			sum+=c[i].x;
			if(sum<=k)
			{
				b[c[i].y]=-1;
			}
			else
			{
				break;
			}
		}
		/*----
		for(i=0;i<=K;i++)
		{
			printf("%d ",b[i]);
		}
		puts("");
		*/
		flag=0;tires = 0;
		for(i=0;i<=K;i++)
		{
			if(b[i]<0 && tires==0)
			{
				ans++;
				tires = 1;
			}
			else if(b[i]>=0 && tires==1)
			{
				ans++;
				tires = 0;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<math.h>
#include<stdlib.h>
#include<stack>
#include<stdio.h>
#include<ctype.h>
#include<map>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
short int ak[1000000];
typedef struct node
{
    int x;
    int y;
    int val;
} ss;
ss app[1000000];
bool cmp(node p,node q)
{   if(p.val == q.val)return p.y<q.y;
    return p.val < q.val;
}
int main(void)
{
    int n,m;
    while(scanf("%d %d",&n,&m)!=EOF)
    {
        int i,sum = 0;
        int ans = 0;
        for(i = 0; i < n; i++)
            scanf("%d",&ak[i]);
        for(i = 0; i < n; i++)
            if(ak[i] < 0)sum++;
        ak[n] = -1;
        if(m < sum)printf("-1\n");
        else
        {
            if(ak[0]<0)
                ans++;
            for(i = 1; i < n; i++)
            {
                if(ak[i]<0&&ak[i-1]>=0)
                    ans++;
                if(ak[i]>=0&&ak[i-1]<0)
                    ans++;
            }
            m-=sum;
            int cn = 0;//printf("%d\n",ans);
            for(i = 1; i < n;)
            {
                if(ak[i-1]<0&&ak[i]>=0)
                {
                    int j;
                    for( j = i; j <= n&&ak[j]>=0;)
                    {
                        j++;
                    }
                    app[cn].x = i;
                    app[cn].y = j-1;
                    i = j+1;
                    app[cn].val = app[cn].y-app[cn].x+1;
                    cn++;
                }
                else i++;
            }
            sort(app,app+cn,cmp);
            for(i = 0; i < cn; i++)
            {
                if(app[i].val <= m)
                    {if(app[i].y!=n-1)ans-=2;
                     else ans--;
                        m -= app[i].val;}
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<math.h>
#include<stdlib.h>
#include<stack>
#include<stdio.h>
#include<ctype.h>
#include<map>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
short int ak[1000000];
typedef struct node
{
    int x;
    int y;
    int val;
} ss;
ss app[1000000];
bool cmp(node p,node q)
{   if(p.val == q.val)return p.y<q.y;
    return p.val < q.val;
}
int main(void)
{
    int n,m;
    while(scanf("%d %d",&n,&m)!=EOF)
    {
        int i,sum = 0;
        int ans = 0;
        for(i = 0; i < n; i++)
            scanf("%d",&ak[i]);
        for(i = 0; i < n; i++)
            if(ak[i] < 0)sum++;
        ak[n] = -1;
        if(m < sum)printf("-1\n");
        else
        {
            if(ak[0]<0)
                ans++;
            for(i = 1; i < n; i++)
            {
                if(ak[i]<0&&ak[i-1]>=0)
                    ans++;
                if(ak[i]>=0&&ak[i-1]<0)
                    ans++;
            }
            m-=sum;
            int cn = 0;//printf("%d\n",ans);
            for(i = 1; i < n;)
            {
                if(ak[i-1]<0&&ak[i]>=0)
                {
                    int j;
                    for( j = i; j <= n&&ak[j]>=0;)
                    {
                        j++;
                    }
                    app[cn].x = i;
                    app[cn].y = j-1;
                    i = j+1;
                    app[cn].val = app[cn].y-app[cn].x+1;
                    cn++;
                }
                else i++;
            }
            if(app[cn-1].y == n-1)
            sort(app,app+cn-1,cmp);
            else sort(app,app+cn,cmp);
            for(i = 0; i < cn; i++)
            {
                if(app[i].val <= m)
                    {if(app[i].y!=n-1)ans-=2;
                     else ans--;
                        m -= app[i].val;}
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<math.h>
#include<stdlib.h>
#include<stack>
#include<stdio.h>
#include<ctype.h>
#include<map>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
short int ak[1000000];
typedef struct node
{
    int x;
    int y;
    int val;
} ss;
ss app[1000000];
bool cmp(node p,node q)
{
    return p.val < q.val;
}
int main(void)
{
    int n,m;
    while(scanf("%d %d",&n,&m)!=EOF)
    {
        int i,sum = 0;
        int ans = 0;
        for(i = 0; i < n; i++)
            scanf("%d",&ak[i]);
        for(i = 0; i < n; i++)
            if(ak[i] < 0)sum++;
        ak[n] = -1;
        if(m < sum)printf("-1\n");
        else
        {
            if(ak[0]<0)
                ans++;
            for(i = 1; i < n; i++)
            {
                if(ak[i]<0&&ak[i-1]>=0)
                    ans++;
                if(ak[i]>=0&&ak[i-1]<0)
                    ans++;
            }
            m-=sum;
            int cn = 0;//printf("%d\n",ans);
            for(i = 1; i < n;)
            {
                if(ak[i-1]<0&&ak[i]>=0)
                {
                    int j;
                    for( j = i; j <= n&&ak[j]>=0;)
                    {
                        j++;
                    }
                    app[cn].x = i;
                    app[cn].y = j-1;
                    i = j+1;
                    app[cn].val = app[cn].y-app[cn].x+1;
                    cn++;
                }
                else i++;
            }
            sort(app,app+cn,cmp);
            for(i = 0; i < cn; i++)
            {
                if(app[i].val <= m)
                    {if(app[i].y!=n-1)ans-=2;
                     else ans--;
                        m -= app[i].val;}
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<math.h>
#include<stdlib.h>
#include<stack>
#include<stdio.h>
#include<ctype.h>
#include<map>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
short int ak[1000000];
typedef struct node
{
    int x;
    int y;
    int val;
} ss;
ss app[1000000];
bool cmp(node p,node q)
{
    return p.val < q.val;
}
int main(void)
{
    int n,m;
    while(scanf("%d %d",&n,&m)!=EOF)
    {
        int i,sum = 0;
        int ans = 0;
        for(i = 0; i < n; i++)
            scanf("%d",&ak[i]);
        for(i = 0; i < n; i++)
            if(ak[i] < 0)sum++;
        ak[n] = -1;
        if(m < sum)printf("-1\n");
        else
        {
            if(ak[0]<0)
                ans++;
            for(i = 1; i < n; i++)
            {
                if(ak[i]<0&&ak[i-1]>=0)
                    ans++;
                if(ak[i]>=0&&ak[i-1]<0)
                    ans++;
            }
            m-=sum;
            int cn = 0;//printf("%d\n",ans);
            for(i = 1; i < n;)
            {
                if(ak[i-1]<0&&ak[i]>=0)
                {
                    int j;
                    for( j = i; j <= n&&ak[j]>=0;)
                    {
                        j++;
                    }
                    app[cn].x = i;
                    app[cn].y = j-1;
                    i = j+1;
                    app[cn].val = app[cn].y-app[cn].x+1;
                    cn++;
                }
                else i++;
            }
            sort(app,app+cn,cmp);
            for(i = 0; i < cn; i++)
            {
                if(app[i].val <= m)
                    ans--;
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<math.h>
#include<stdlib.h>
#include<stack>
#include<stdio.h>
#include<ctype.h>
#include<map>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
short int ak[1000000];
typedef struct node
{
    int x;
    int y;
    int val;
} ss;
ss app[1000000];
bool cmp(node p,node q)
{   if(p.val == q.val)return p.y<q.y;
    return p.val < q.val;
}
int main(void)
{
    int n,m;
    while(scanf("%d %d",&n,&m)!=EOF)
    {
        int i,sum = 0;
        int ans = 0;
        for(i = 0; i < n; i++)
            scanf("%d",&ak[i]);
        for(i = 0; i < n; i++)
            if(ak[i] < 0)sum++;
        ak[n] = -1;
        if(m < sum)printf("-1\n");
        else
        {
            if(ak[0]<0)
                ans++;
            for(i = 1; i < n; i++)
            {
                if(ak[i]<0&&ak[i-1]>=0)
                    ans++;
                if(ak[i]>=0&&ak[i-1]<0)
                    ans++;
            }
            m-=sum;
            int cn = 0;//printf("%d\n",ans);
            for(i = 1; i < n;)
            {
                if(ak[i-1]<0&&ak[i]>=0)
                {
                    int j;
                    for( j = i; j <= n&&ak[j]>=0;)
                    {
                        j++;
                    }
                    app[cn].x = i;
                    app[cn].y = j-1;
                    i = j+1;
                    app[cn].val = app[cn].y-app[cn].x+1;
                    cn++;
                }
                else i++;
            }
            if(app[cn-1].y == n-1&&cn>0)
            sort(app,app+cn-1,cmp);
            else sort(app,app+cn,cmp);
            for(i = 0; i < cn; i++)
            {
                if(app[i].val <= m)
                    {if(app[i].y!=n-1)ans-=2;
                     else ans--;
                        m -= app[i].val;}
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,k,sum1=0,sum2;
int current=0;
int a[200009],negative[200009],g=0;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++)
    {
		cin>>a[i];
	}
	int s=1;
	while(a[s]>=0 && s<=n)
	{
		s++;
	}
	for(int i=s;i<=n;i++)
	{
		if( (a[i]>=0) != (a[i-1]>=0) )
		{
			sum1++;
		}
		if(a[i]<0)
		{
			if(current>0)
			{
				negative[g++]=current;
			}
			current=0;
			k--;
		}
        else
		{
			current++;
		}
	}
	if(k<0)
    {
		cout<<-1<<endl;
		return 0;
	}
	sum2=sum1;
	sort(negative,negative+g);
	if(current>0 && k>=current){
		int b=k-current;
		sum2--;
		for(int i=0;i<g;i++){
			if(negative[i]<=b){
				b-=negative[i];
				sum2-=2;
			}
		}
	}
	for(int i=0;i<g;i++){
		if(negative[i]<=k){
			k-=negative[i];
			sum1-=2;
		}
	}
	int mn;
	mn=min(sum1,sum2);
	cout<<mn<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int n,k,sum1=0,sum2;
int current=0;
int a[200009],negative[200009],g=0;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++)
    {
		cin>>a[i];
	}
	int s=1;
	while(a[s]>=0 && s<=n)
	{
		s++;
	}
	for(int i=s;i<=n;i++)
	{
		if( (a[i]>=0) != (a[i-1]>=0) )
		{
			sum1++;
		}
		if(a[i]<0)
		{
			if(current>0)
			{
				negative[g++]=current;
			}
			current=0;
			k--;
		}
        else
		{
			current++;
		}
	}
	if(k<0)
    {
		cout<<"IMPOSSIBLE"<<endl;
		return 0;
	}
	sum2=sum1;
	sort(negative,negative+g);
	if(current>0 && k>=current){
		int b=k-current;
		sum2--;
		for(int i=0;i<g;i++){
			if(negative[i]<=b){
				b-=negative[i];
				sum2-=2;
			}
		}
	}
	for(int i=0;i<g;i++){
		if(negative[i]<=k){
			k-=negative[i];
			sum1-=2;
		}
	}
	int mn;
	mn=min(sum1,sum2);
	cout<<mn<<endl;
}


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;

int n,k;
int arr[200100];
int gap[200200],g=0;
int main(){
	cin.sync_with_stdio(false);
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>arr[i];
	}
	int s=1;
	while(arr[s]>=0 && s<=n){
		s++;
	}
	int cur=0;
	int sol=0;
	int sol2;
	for(int i=s;i<=n;i++){
		if( (arr[i]>=0) != (arr[i-1]>=0) ){
			sol++;
		}
		if(arr[i]<0){
			if(cur>0){
				gap[g++]=cur;
			}
			cur=0;
			k--;
		} else {
			cur++;
		}
	}
	if(k<0){
		cout<<-1<<endl;
		return 0;
	}
	sol2=sol;
	sort(gap,gap+g);
	if(cur>0 && k>=cur){
		int kk=k-cur;
		sol2--;
		for(int i=0;i<g;i++){
			if(gap[i]<=kk){
				kk-=gap[i];
				sol2-=2;
			}
		}
	}
	for(int i=0;i<g;i++){
		if(gap[i]<=k){
			k-=gap[i];
			sol-=2;
		}
	}
	cout<<min(sol,sol2)<<endl;

}


#include <iostream>
#include "algorithm"
using namespace std;

int main() {
    int n,k;
    cin>>n>>k;
    int t[n+1];
    int i;
    int g=0,flag[n+1],flag2[n+1];
    for(i=1;i<=n;i++){
        cin>>t[i];
        if(t[i]<0)
            g++;
    }
    if(g>k)
    {
        cout<<-1;
        return 0;
    }
    int num=0,num2=0;
    for(int i=1;i<=n;i++){
        if(t[i]<0){
            num++;
            flag[i]=0;
            if(num==1)
                continue;
            int k=0;
            while(t[i-(++k)]>=0);
            flag2[num2++]=k-1;
        }
    }
    for(i=n;i>=1;i--)
    {
        if(flag[i]==0)
            break;
    }
    int ende=0,endi=0;
    if(i!=n)
    flag2[num2++]=n-i,ende=1,endi=n-i;
    if(!ende)
    sort(flag2,flag2+num2);
    else
        sort(flag2,flag2+num2-1);
    int m=k-num;
    int c2=0;
    if(ende==0){
        for(i=0;i<num2;i++){
            if((m-=flag2[i])>=0)
                c2++;
            if(m<=0)
                break;
        }
    }
    else{
        int c3=0,c4=0,m3=m,m4=m;
        for(i=0;i<num2-1;i++)
        {
            if((m3-=flag2[i])>=0)
                c3++;
            if(m3<=0)
                break;
        }
        sort(flag2,flag2+num2);
        for(i=0;i<num2;i++)
        {
            if((m4-=flag2[i])>=0)
                c4++;
            if(m4==0)
                break;
            if(m4<0)
            {
                i--;
                break;
            }
        }
            if(c4>c3)
            {
                c2=c4;
                //cout<<i<<' '<<num2<<' '<<flag2[i+1]<<' '<<endi<<endl;
                if(i==num2||i+1==num2||flag2[++i]>endi)
                    ende=0;
            }
            else
            c2=c3;

    }
    //cout<<num2<<' '<<c2<<' '<<ende<<endl;
    if(num==0){
        cout<<0;
        return 0;
    }
    else if(num==n){
        cout<<1;
        return 0;
    }
    else{
        cout<<(num2-c2)*2+1-ende;
    }
    return 0;
}


#include <iostream>
#include "algorithm"
using namespace std;

int main() {
    int n,k;
    cin>>n>>k;
    int t[n+1];
    int i;
    int g=0,flag[n+1],flag2[n+1];
    for(i=1;i<=n;i++){
        cin>>t[i];
        if(t[i]<0)
            g++;
    }
    if(g>k)
    {
        cout<<-1;
        return 0;
    }
    int num=0,num2=0;
    for(int i=1;i<=n;i++){
        if(t[i]<0){
            num++;
            flag[i]=0;
            if(num==1)
                continue;
            int k=0;
            while(t[i-(++k)]>=0);
            flag2[num2++]=k-1;
        }
    }
    for(i=n;i>=1;i--)
    {
        if(flag[i]==0)
            break;
    }
    int ende=0,endi=0;
    if(i!=n)
    flag2[num2++]=n-i,ende=1,endi=n-i;
    if(!ende)
    sort(flag2,flag2+num2);
    else
        sort(flag2,flag2+num2-1);
    int m=k-num;
    int c2=0;
    if(ende==0){
        for(i=0;i<num2;i++){
            if((m-=flag2[i])>=0)
                c2++;
            if(m<=0)
                break;
        }
    }
    else{
        int c3=0,c4=0,m3=m,m4=m;
        for(i=0;i<num2-1;i++)
        {
            if((m3-=flag2[i])>=0)
                c3++;
            if(m3<=0)
                break;
        }
        sort(flag2,flag2+num2);
        for(i=0;i<num2;i++)
        {
            if((m4-=flag2[i])>=0)
                c4++;
            if(m4<=0)
                break;
        }
        if(c4>c3)
        {
            c2=c4;
            if(i==num2||flag2[i++]>endi)
                ende=0;
        }
        else
            c2=c3;

    }
    if(num==0){
        cout<<0;
        return 0;
    }
    else if(num==n){
        cout<<1;
        return 0;
    }
    else{
        cout<<(num2-c2)*2+1-ende;
    }
    return 0;
}


#include <iostream>
#include "algorithm"
using namespace std;

int main() {
    int n,k;
    cin>>n>>k;
    int t[n+1];
    int i;
    int g=0,flag[n+1],flag2[n+1];
    for(i=1;i<=n;i++){
        cin>>t[i];
        flag[i]=1;
        if(t[i]<0)
            g++;
    }
    if(g>k)
    {
        cout<<-1;
        return 0;
    }
    int num=0,num2=0;
    for(int i=1;i<=n;i++){
        if(t[i]<0){
            num++;
            flag[i]=0;
            if(num==1)
                continue;
            int k=0;
            while(t[i-(++k)]>=0);
            flag2[num2++]=k-1;
        }
    }
    for(i=n;i>=1;i--)
    {
        if(flag[i]==0)
            break;
    }
    int ende=0,endi=0;
    if(i!=n)
    flag2[num2++]=n-i,ende=1,endi=n-i;
    if(!ende)
    sort(flag2,flag2+num2);
    else
        sort(flag2,flag2+num2-1);
    int m=k-num;
    int c2=0;
    if(ende==0){
        for(i=0;i<num2;i++){
            if((m-=flag2[i])>=0)
                c2++;
            if(m<=0)
                break;
        }
    }
    else{
        int c3=0,c4=0,m3=m,m4=m;
        for(i=0;i<num2-1;i++)
        {
            if((m3-=flag2[i])>=0)
                c3++;
            if(m3<=0)
                break;
        }
        sort(flag2,flag2+num2);
        for(i=0;i<num2;i++)
        {
            if((m4-=flag2[i])>=0)
                c4++;
            if(m4==0)
                break;
            if(m4<0)
            {
                i--;
                break;
            }
        }
            if(c4>c3)
            {
                c2=c4;
                //cout<<i<<' '<<num2<<' '<<flag2[i+1]<<' '<<endi<<endl;
                if(i==num2||i+1==num2||flag2[++i]>endi)
                    ende=0;
            }
            else
            c2=c3;

    }
    //cout<<num2<<' '<<c2<<' '<<ende<<endl;
    if(num==0){
        cout<<0;
        return 0;
    }
    else{
        cout<<(num2-c2)*2+1-ende;
    }
    return 0;
}


#include <iostream>
#include "algorithm"
using namespace std;

int main() {
    int n,k;
    cin>>n>>k;
    int t[n+1];
    int i;
    int g=0,flag[n+1],flag2[n+1];
    for(i=1;i<=n;i++){
        cin>>t[i];
        flag[i]=1;
        if(t[i]<0)
            g++;
    }
    if(g>k)
    {
        cout<<-1;
        return 0;
    }
    int num=0,num2=0;
    for(int i=1;i<=n;i++){
        if(t[i]<0){
            num++;
            flag[i]=0;
            if(num==1)
                continue;
            int k=0;
            while(t[i-(++k)]>=0);
            flag2[num2++]=k-1;
        }
    }
    for(i=n;i>=1;i--)
    {
        if(flag[i]==0)
            break;
    }
    int ende=0,endi=0;
    if(i!=n)
    flag2[num2++]=n-i,ende=1,endi=n-i;
    if(!ende)
    sort(flag2,flag2+num2);
    else
        sort(flag2,flag2+num2-1);
    int m=k-num;
    int c2=0;
    if(ende==0){
        for(i=0;i<num2;i++){
            if((m-=flag2[i])>=0)
                c2++;
            if(m<=0)
                break;
        }
    }
    else{
        int c3=0,c4=0,m3=m,m4=m;
        for(i=0;i<num2-1;i++)
        {
            if((m3-=flag2[i])>=0)
                c3++;
            if(m3<=0)
                break;
        }
        sort(flag2,flag2+num2);
        for(i=0;i<num2;i++)
        {
            if((m4-=flag2[i])>=0)
                c4++;
            if(m4==0)
                break;
            if(m4<0)
            {
                i--;
                break;
            }
        }
            if(c4>c3)
            {
                c2=c4;
                //cout<<i<<' '<<num2<<' '<<flag2[i+1]<<' '<<endi<<endl;
                if(i==num2||i+1==num2||flag2[++i]>endi)
                    ende=0;
            }
            else
            c2=c3;

    }
    //cout<<num2<<' '<<c2<<' '<<ende<<endl;
    if(num==0){
        cout<<0;
        return 0;
    }
    else if(num==n){
        cout<<1;
        return 0;
    }
    else{
        cout<<(num2-c2)*2+1-ende;
    }
    return 0;
}


#include <iostream>
#include "algorithm"
using namespace std;

int main() {
    int n,k;
    cin>>n>>k;
    int t[n+1];
    int i;
    int g=0,flag[n+1],flag2[n+1];
    for(i=1;i<=n;i++){
        cin>>t[i];
        if(t[i]<0)
            g++;
    }
    if(g>k)
    {
        cout<<-1;
        return 0;
    }
    int num=0,num2=0;
    for(int i=1;i<=n;i++){
        if(t[i]<0){
            num++;
            flag[i]=0;
            if(num==1)
                continue;
            int k=0;
            while(t[i-(++k)]>=0);
            flag2[num2++]=k-1;
        }
    }
    for(i=n;i>=1;i--)
    {
        if(flag[i]==0)
            break;
    }
    int ende=0;
    if(i!=n)
    flag2[num2++]=n-i,ende=1;
    sort(flag2,flag2+num2);
    int m=k-num;
    int c2=0;
    for(i=0;i<num2;i++)
    {
        if((m-=flag2[i])>=0)
            c2++;
        if(m<=0)
            break;
    }
    if(num==0){
        cout<<0;
        return 0;
    }
    else if(num==n){
        cout<<1;
        return 0;
    }
    else{
        cout<<(num2-c2)*2+1-ende;
    }
    return 0;
}


#include <iostream>
#include "algorithm"
using namespace std;

int main() {
    int n,k;
    cin>>n>>k;
    int t[n+1];
    int i;
    int g=0,flag[n+1],flag2[n+1];
    for(i=1;i<=n;i++){
        cin>>t[i];
        if(t[i]<0)
            g++;
    }
    if(g>k)
        cout<<-1;
    int num=0,num2=0;
    for(int i=1;i<=n;i++){
        if(t[i]<0){
            num++;
            flag[i]=0;
            if(num==1)
                continue;
            int k=0;
            while(t[i-(++k)]>=0);
            flag2[num2++]=k-1;
        }
    }
    for(i=n;i>=1;i--)
    {
        if(flag[i]==0)
            break;
    }
    int ende=0;
    if(i!=n)
    flag2[num2++]=n-i,ende=1;
    sort(flag2,flag2+num2);
    int m=k-num;
    int c2=0;
    for(i=0;i<num2;i++)
    {
        if((m-=flag2[i])>=0)
            c2++;
        if(m<=0)
            break;
    }
    if(num==0){
        cout<<0;
        return 0;
    }
    else if(num==n){
        cout<<1;
        return 0;
    }
    else{
        cout<<(num2-c2)*2+1-ende;
    }
    return 0;
}


#include <iostream>
#include "algorithm"
using namespace std;

int main() {
    int n,k;
    cin>>n>>k;
    int t[n+1];
    int i;
    int g=0,flag[n+1],flag2[n+1];
    for(i=1;i<=n;i++){
        cin>>t[i];
        flag[i]=1;
        if(t[i]<0)
            g++;
    }
    if(g>k)
    {
        cout<<-1;
        return 0;
    }
    int num=0,num2=0;
    for(int i=1;i<=n;i++){
        if(t[i]<0){
            num++;
            flag[i]=0;
            if(num==1)
                continue;
            int k=0;
            while(t[i-(++k)]>=0);
            if(k==1)
                continue;
            flag2[num2++]=k-1;
        }
    }
    for(i=n;i>=1;i--)
    {
        if(flag[i]==0)
            break;
    }
    int ende=0,endi=0;
    if(i!=n)
    flag2[num2++]=n-i,ende=1,endi=n-i;
    if(!ende)
    sort(flag2,flag2+num2);
    else
        sort(flag2,flag2+num2-1);
    int m=k-num;
    int c2=0;
    if(ende==0){
        for(i=0;i<num2;i++){
            if((m-=flag2[i])>=0)
                c2++;
            if(m<=0)
                break;
        }
    }
    else{
        int c3=0,c4=0,m3=m,m4=m;
        for(i=0;i<num2-1;i++)
        {
            if((m3-=flag2[i])>=0)
                c3++;
            if(m3<=0)
                break;
        }
        sort(flag2,flag2+num2);
        for(i=0;i<num2;i++)
        {
            if((m4-=flag2[i])>=0)
                c4++;
            if(m4==0)
                break;
            if(m4<0)
            {
                i--;
                break;
            }
        }
            if(c4>c3)
            {
                c2=c4;
                //cout<<i<<' '<<num2<<' '<<flag2[i+1]<<' '<<endi<<endl;
                if(i==num2||i+1==num2||flag2[++i]>endi)
                    ende=0;
            }
            else
            c2=c3;

    }
    //cout<<num2<<' '<<c2<<' '<<ende<<endl;
    if(num==0){
        cout<<0;
        return 0;
    }
    else{
        cout<<(num2-c2)*2+1-ende;
    }
    return 0;
}


#include <iostream>
#include "algorithm"
#include "stdio.h"
using namespace std;

int main() {
    int n,k;
    cin>>n>>k;
    int t[n+1];
    int i;
    int g=0,flag[n+1],flag2[n+1];
    for(i=1;i<=n;i++){
        scanf("%d",&t[i]);
        flag[i]=1;
        if(t[i]<0)
            g++;
    }
    if(g>k)
    {
        cout<<-1;
        return 0;
    }
    int num=0,num2=0;
    for(int i=1;i<=n;i++){
        if(t[i]<0){
            num++;
            flag[i]=0;
            if(num==1)
                continue;
            int k=0;
            while(t[i-(++k)]>=0);
            if(k==1)
                continue;
            flag2[num2++]=k-1;
        }
    }
    for(i=n;i>=1;i--)
    {
        if(flag[i]==0)
            break;
    }
    int ende=0,endi=0;
    if(i!=n)
    flag2[num2++]=n-i,ende=1,endi=n-i;
    if(!ende)
    sort(flag2,flag2+num2);
    else
        sort(flag2,flag2+num2-1);
    int m=k-num;
    int c2=0;
    if(ende==0){
        for(i=0;i<num2;i++){
            if((m-=flag2[i])>=0)
                c2++;
            if(m<=0)
                break;
        }
    }
    else{
        int c3=0,c4=0,m3=m,m4=m;
        for(i=0;i<num2-1;i++)
        {
            if((m3-=flag2[i])>=0)
                c3++;
            if(m3<=0)
                break;
        }
        sort(flag2,flag2+num2);
        for(i=0;i<num2;i++)
        {
            if((m4-=flag2[i])>=0)
                c4++;
            if(m4==0)
                break;
            if(m4<0)
            {
                i--;
                break;
            }
        }
            if(c4>c3)
            {
                c2=c4;
                //cout<<i<<' '<<num2<<' '<<flag2[i+1]<<' '<<endi<<endl;
                if(i==num2||i+1==num2||flag2[++i]>endi)
                    ende=0;
            }
            else
            c2=c3;

    }
    //cout<<num2<<' '<<c2<<' '<<ende<<endl;
    if(num==0){
        cout<<0;
        return 0;
    }
    else{
        cout<<(num2-c2)*2+1-ende;
    }
    return 0;
}


#include <iostream>
#include "algorithm"
#include "stdio.h"
#include"string.h"
using namespace std;

int main() {
    int n,k;
    cin>>n>>k;
    int t[n+1];
    int i;
    int g=0,flag[n+1],flag2[n+1];
    for(i=1;i<=n;i++){
        scanf("%d",&t[i]);
        //flag[i]=1;
        if(t[i]<0)
            g++;
    }
    memset(flag,-1,sizeof(flag));
    if(g>k)
    {
        cout<<-1;
        return 0;
    }
    int num=0,num2=0;
    for(int i=1;i<=n;i++){
        if(t[i]<0){
            num++;
            flag[i]=0;
            if(num==1)
                continue;
            int k=0;
            while(t[i-(++k)]>=0);
            if(k==1)
                continue;
            flag2[num2++]=k-1;
        }
    }
    for(i=n;i>=1;i--)
    {
        if(flag[i]==0)
            break;
    }
    int ende=0,endi=0;
    if(i!=n)
    flag2[num2++]=n-i,ende=1,endi=n-i;
    if(!ende)
    sort(flag2,flag2+num2);
    else
        sort(flag2,flag2+num2-1);
    int m=k-num;
    int c2=0;
    if(ende==0){
        for(i=0;i<num2;i++){
            if((m-=flag2[i])>=0)
                c2++;
            if(m<=0)
                break;
        }
    }
    else{
        int c3=0,c4=0,m3=m,m4=m;
        for(i=0;i<num2-1;i++)
        {
            if((m3-=flag2[i])>=0)
                c3++;
            if(m3<=0)
                break;
        }
        sort(flag2,flag2+num2);
        for(i=0;i<num2;i++)
        {
            if((m4-=flag2[i])>=0)
                c4++;
            if(m4==0)
                break;
            if(m4<0)
            {
                i--;
                break;
            }
        }
            if(c4>c3)
            {
                c2=c4;
                //cout<<i<<' '<<num2<<' '<<flag2[i+1]<<' '<<endi<<endl;
                if(i==num2||i+1==num2||flag2[++i]>endi)
                    ende=0;
            }
            else
            c2=c3;

    }
    //cout<<num2<<' '<<c2<<' '<<ende<<endl;
    if(num==0){
        cout<<0;
        return 0;
    }
    else{
        cout<<(num2-c2)*2+1-ende;
    }
    return 0;
}


#include <iostream>
#include "algorithm"
using namespace std;

int main() {
    int n,k;
    cin>>n>>k;
    int t[n+1];
    int i;
    int g=0,flag[n+1],flag2[n+1];
    for(i=1;i<=n;i++){
        cin>>t[i];
        if(t[i]<0)
            g++;
    }
    if(g>k)
    {
        cout<<-1;
        return 0;
    }
    int num=0,num2=0;
    for(int i=1;i<=n;i++){
        if(t[i]<0){
            num++;
            flag[i]=0;
            if(num==1)
                continue;
            int k=0;
            while(t[i-(++k)]>=0);
            flag2[num2++]=k-1;
        }
    }
    for(i=n;i>=1;i--)
    {
        if(flag[i]==0)
            break;
    }
    int ende=0,endi=0;
    if(i!=n)
    flag2[num2++]=n-i,ende=1,endi=n-i;
    if(!ende)
    sort(flag2,flag2+num2);
    else
        sort(flag2,flag2+num2-1);
    int m=k-num;
    int c2=0;
    if(ende==0){
        for(i=0;i<num2;i++){
            if((m-=flag2[i])>=0)
                c2++;
            if(m<=0)
                break;
        }
    }
    else{
        int c3=0,c4=0,m3=m,m4=m;
        for(i=0;i<num2-1;i++)
        {
            if((m3-=flag2[i])>=0)
                c3++;
            if(m3<=0)
                break;
        }
        sort(flag2,flag2+num2);
        for(i=0;i<num2;i++)
        {
            if((m4-=flag2[i])>=0)
                c4++;
            if(m4<=0)
                break;
        }
        if(c4>c3)
        {
            c2=c4;
            //cout<<i<<' '<<num2<<' '<<flag2[i+1]<<' '<<endi<<endl;
            if(i==num2||i+1==num2||flag2[i++]>endi)
                ende=0;
        }
        else
            c2=c3;

    }
    //cout<<num2<<' '<<c2<<' '<<ende<<endl;
    if(num==0){
        cout<<0;
        return 0;
    }
    else if(num==n){
        cout<<1;
        return 0;
    }
    else{
        cout<<(num2-c2)*2+1-ende;
    }
    return 0;
}


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

int main() {

	int n,k,cnt=0,i=1,a[1000006],t=0,ans,days,last,flag=0;

	cin>>n>>k;

	while(i<=n)
	{
		cin>>t;
		if(t<0) {flag=1;break;}
		i++;
	}

	while(i<=n)
	{
		int j=i+1;

		while(j<=n)
		{
			cin>>t;
			if(t<0) break;
			j++;
		}

		if(j<=n)
		{
			a[cnt]=j-i-1;

			cnt++;
		}

		else
		{
			last=j-i-1;
		}

		i=j;

	}

	if(flag==0)
	{
	    printf("0");
	    return 0;
	}

	ans=2*(cnt+1);

	days=cnt+1;

	if(days>k)
	{
		cout<<"-1";
		return 0;
	}
	sort(a,a+cnt);

	i=0;

	while(i<cnt)
	{
		if((a[i]+days)<=k)
		{
			ans-=2;
			days+=a[i];
		}
		else break;

		i++;
	}

	if((k-days)>=last) ans--;
	cout<<ans;

	return 0;
}


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

int main() {

	int n,k,cnt=0,i=1,a[1000006],t=0,ans,days,last;

	cin>>n>>k;

	while(i<=n)
	{
		cin>>t;
		if(t<0) break;
		i++;
	}

	while(i<=n)
	{
		int j=i+1;

		while(j<=n)
		{
			cin>>t;
			if(t<0) break;
			j++;
		}

		if(j<=n)
		{
			a[cnt]=j-i-1;

			cnt++;
		}

		else
		{
			last=j-i-1;
		}

		i=j;

	}

	if(cnt==0)
	{
	    printf("0");
	    return 0;
	}

	ans=2*(cnt+1);

	days=cnt+1;

	if(days>k)
	{
		cout<<"-1";
		return 0;
	}
	sort(a,a+cnt);

	i=0;

	while(i<cnt)
	{
		if((a[i]+days)<=k)
		{
			ans-=2;
			days+=a[i];
		}
		else break;

		i++;
	}

	if((k-days)>=last) ans--;
	cout<<ans;

	return 0;
}


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

int main() {

	int n,k,cnt=0,i=1,a[1000006],t=0,ans,days,last;

	cin>>n>>k;

	while(i<=n)
	{
		cin>>t;
		if(t<0) break;
		i++;
	}

	while(i<=n)
	{
		int j=i+1;

		while(j<=n)
		{
			cin>>t;
			if(t<0) break;
			j++;
		}

		if(j<=n)
		{
			a[cnt]=j-i-1;

			cnt++;
		}

		else
		{
			last=j-i-1;
		}

		i=j;

	}

	ans=2*(cnt+1);

	days=cnt+1;

	if(days>k)
	{
		cout<<"-1";
		return 0;
	}
	sort(a,a+cnt);

	i=0;

	while(i<cnt)
	{
		if((a[i]+days)<=k)
		{
			ans-=2;
			days+=a[i];
		}
		else break;

		i++;
	}

	if((k-days)>=last) ans--;
	cout<<ans;

	return 0;
}


int main() {

	int n,k,cnt=0,i=1,a[1000006],t=0,ans,days,last;

	cin>>n>>k;

	while(i<=n)
	{
		cin>>t;
		if(t<0) break;
		i++;
	}

	while(i<=n)
	{
		int j=i+1;

		while(j<=n)
		{
			cin>>t;
			if(t<0) break;
			j++;
		}

		if(j<=n)
		{
			a[cnt]=j-i-1;

			cnt++;
		}

		else
		{
			last=j-i-1;
		}

		i=j;

	}

	if(cnt==0)
	{
	    printf("0");
	    return 0;
	}

	ans=2*(cnt+1);

	days=cnt+1;

	if(days>k)
	{
		cout<<"-1";
		return 0;
	}
	sort(a,a+cnt);

	i=0;

	while(i<cnt)
	{
		if((a[i]+days)<=k)
		{
			ans-=2;
			days+=a[i];
		}
		else break;

		i++;
	}

	if((k-days)>=last) ans--;
	cout<<ans;

	return 0;
}


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

int main() {

	int n,k,cnt=0,i=1,a[1000006],t=0,ans,days,last;

	cin>>n>>k;

	while(i<=n)
	{
		cin>>t;
		if(t<0){cnt++; break;}
		i++;
	}

	while(i<=n)
	{
		int j=i+1;

		while(j<=n)
		{
			cin>>t;
			if(t<0) break;
			j++;
		}

		if(j<=n)
		{
			a[cnt]=j-i-1;

			cnt++;
		}

		else
		{
			last=j-i-1;
		}

		i=j;

	}

	ans=2*(cnt);

	days=cnt;

	if(cnt==0)
	{
	    printf("0");
	    return 0;
	}

	if(days>k)
	{
		cout<<"-1";
		return 0;
	}
	sort(a,a+cnt);

	i=0;

	while(i<cnt)
	{
		if((a[i]+days)<=k)
		{
			ans-=2;
			days+=a[i];
		}
		else break;

		i++;
	}

	if((k-days)>=last) ans--;
	cout<<ans;

	return 0;
}


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

int main() {

	int n,k,cnt=0,i=1,a[1000006],t=0,ans,days,last;

	cin>>n>>k;

	while(i<=n)
	{
		cin>>t;
		if(t<0) break;
		i++;
	}

	while(i<=n)
	{
		int j=i+1;

		while(j<=n)
		{
			cin>>t;
			if(t<0) break;
			j++;
		}

		if(j<=n)
		{
			a[cnt]=j-i-1;

			cnt++;
		}

		else
		{
			last=j-i-1;
		}

		i=j;

	}

	ans=2*(cnt+1);

	days=cnt+1;

	if(days>k)
	{
		cout<<"-1";
		return 0;
	}
	sort(a,a+cnt);

	if(cnt==0)
	{
	    printf("0");
	    return 0;
	}

	i=0;

	while(i<cnt)
	{
		if((a[i]+days)<=k)
		{
			ans-=2;
			days+=a[i];
		}
		else break;

		i++;
	}

	if((k-days)>=last) ans--;
	cout<<ans;

	return 0;
}


#include <iostream>
#include <queue>
using namespace std;

int main()
{
	priority_queue<int> length;
	int n,k;
	cin>>n>>k;
	int t;
	cin>>t;
	int lastIdx = (t<0)?0:-1;
	int res = (t<0)?1:0;
	int prev = t;
	int count = res;
	for(int i=1;i<n;i++)
	{
		cin>>t;
		if((t<0 && prev>=0) || (prev<0 && t>=0))
			res++;
		if(t<0)
		{
			if(lastIdx!=-1 && lastIdx!=i-1)
			{
				length.push(lastIdx+1-i);
			}
			lastIdx = i;
			count++;
		}
		prev = t;
	}
	if(k<count)
		cout<<-1<<"\n";
	else
	{
		k-=count;
		while(!length.empty())
		{
			int num = -length.top();
			if(k>=num)
			{
				k-=num;
				length.pop();
				res-=2;
			}
			else
				break;
		}
		if(k>=n-lastIdx-1 && res>1)
			res--;
		cout<<res<<"\n";
	}
	return 0;
}


#include <iostream>
#include <queue>
using namespace std;

int main()
{
	priority_queue<int> length;
	int n,k;
	cin>>n>>k;
	int t;
	cin>>t;
	int lastIdx = (t<0)?0:-1;
	int res = (t<0)?1:0;
	int prev = t;
	int count = res;
	for(int i=1;i<n;i++)
	{
		cin>>t;
		if((t<0 && prev>=0) || (prev<0 && t>=0))
			res++;
		if(t<0)
		{
			if(lastIdx!=-1 && lastIdx!=i-1)
			{
				length.push(lastIdx+1-i);
			}
			lastIdx = i;
			count++;
		}
		prev = t;
	}
	if(k<count)
		cout<<-1<<"\n";
	else
	{
		k-=count;
		while(!length.empty())
		{
			int num = -length.top();
			if(k>=num)
			{
				k-=num;
				length.pop();
				res-=2;
			}
			else
				break;
		}
		if(k>=n-lastIdx-1 && lastIdx!=n-1)
			res--;
		cout<<res<<"\n";
	}
	return 0;
}


#include <iostream>
#include <queue>
using namespace std;

int main()
{
	priority_queue<int> length;
	int n,k;
	cin>>n>>k;
	int t;
	cin>>t;
	int lastIdx = (t<0)?0:-1;
	int res = (t<0)?1:0;
	int prev = t;
	int count = res;
	for(int i=1;i<n;i++)
	{
		cin>>t;
		if((t<0 && prev>=0) || (prev<0 && t>=0))
			res++;
		if(t<0)
		{
			if(lastIdx!=-1 && lastIdx!=i-1)
			{
				length.push(lastIdx+1-i);
			}
			lastIdx = i;
			count++;
		}
		prev = t;
	}
	if(k<count)
		cout<<-1<<"\n";
	else
	{
		k-=count;
		while(!length.empty())
		{
			int num = -length.top();
			if(k>=num)
			{
				k-=num;
				length.pop();
				res-=2;
			}
			else
				break;
		}
		if(k>=n-lastIdx-1 && lastIndex!=n-1)
			res--;
		cout<<res<<"\n";
	}
	return 0;
}


#include <iostream>
#include <queue>
using namespace std;

int main()
{
	priority_queue<int> length;
	int n,k;
	cin>>n>>k;
	int t;
	cin>>t;
	int lastIdx = (t<0)?0:-1;
	int res = (t<0)?1:0;
	int prev = t;
	int count = res;
	for(int i=1;i<n;i++)
	{
		cin>>t;
		if((t<0 && prev>=0) || (prev<0 && t>=0))
			res++;
		if(t<0)
		{
			if(lastIdx!=-1 && lastIdx!=i-1)
			{
				length.push(lastIdx+1-i);
			}
			lastIdx = i;
			count++;
		}
		prev = t;
	}
	if(k<count)
		cout<<-1<<"\n";
	else
	{
		k-=count;
		while(!length.empty())
		{
			int num = -length.top();
			if(k>=num)
			{
				k-=num;
				length.pop();
				res-=2;
			}
			else
				break;
		}
		if(k>=n-lastIdx-1)
			res--;
		cout<<res<<"\n";
	}
	return 0;
}


#include <iostream>
#include <queue>
using namespace std;

int main()
{
	priority_queue<int> length;
	int n,k;
	cin>>n>>k;
	int t;
	cin>>t;
	int lastIdx = (t<0)?0:-1;
	int res = (t<0)?1:0;
	int prev = t;
	int count = res;
	for(int i=1;i<n;i++)
	{
		cin>>t;
		if((t<0 && prev>=0) || (prev<0 && t>=0))
			res++;
		if(t<0)
		{
			if(lastIdx!=-1 && lastIdx!=i-1)
			{
				length.push(lastIdx+1-i);
			}
			lastIdx = i;
			count++;
		}
		prev = t;
	}
	if(k<count)
		cout<<-1<<"\n";
	else
	{
		k-=count;
		while(!length.empty())
		{
			int num = -length.top();
			if(k>=num)
			{
				k-=num;
				length.pop();
				res-=2;
			}
			else
				break;
		}
		if(k>=n-lastIdx-1 && lastIdx!=n-1 && lastIdx!=-1)
			res--;
		cout<<res<<"\n";
	}
	return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn=2e5+1e2;
const int INF=2e9;

int a[maxn],num[maxn],cnt=0,num1=INF,num2=INF;

int getint()
{
	char ch;int b=1;
	for(ch=getchar();ch>'9'||ch<'0';ch=getchar())if(ch=='-')b=-1;
	int num=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar())num=num*10+ch-'0';
	return num*b;
}

int main()
{
	int n=getint(),k=getint();
	int las=0,ans=0;
	for(int i=1;i<=n;i++)a[i]=getint();
	for(int i=1;i<=n;i++)
	{
		if(a[i-1]<0&&a[i]>=0)ans++;
		if(a[i-1]>=0&&a[i]<0)ans++;
		if(a[i]<0)
		{
			k--;
			if(las!=i-1||i==1)
			{
				if(i!=1)
				{
					if(las!=0)num[++cnt]=i-las-1;
					else num2=i-las-1;
				}
			}
			las=i;
		}
	}
	if(las!=n)num1=n-las;
	sort(num+1,num+cnt+1);
	for(int i=1;i<=cnt;i++)
	{
		if(k<=0)break;
		if(k>=num[i])
		{
			ans-=2;
			k-=num[i];
		}
	}
	/*printf("%d:",k);
	for(int i=1;i<=cnt;i++)printf("%d ",num[i]);
	printf("%d\n",num1);*/
	if(k>=num1)
	{
		ans--;
		k-=num1;
	}
	if(k<0)printf("-1\n");
	else printf("%d\n",ans);
	return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn=2e5+1e2;

int a[maxn],c[maxn],cnt=0;

int getint()
{
	char ch;int b=1;
	for(ch=getchar();ch>'9'||ch<'0';ch=getchar())if(ch=='-')b=-1;
	int num=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar())num=num*10+ch-'0';
	return num*b;
}

int main()
{
	int n=getint(),k=getint();
	for(int i=1;i<=n;i++)
	{
		a[i]=getint();
	}
	int have=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]<0&&have>0)
		{
			c[++cnt]=have;
			have=0;
		}
		if(a[i]>=0)have++;
	}
	if(have>0)c[++cnt]=have;
	sort(c+1,c+cnt+1);
	int ans=1,all=n,last;
	for(int i=cnt;i>=1;i--)
	{
		if(all>k)
		{
			all-=c[i];
			last=c[i];
			ans+=2;
		}
		else break;
	}
	if(all>k)
	{
		printf("-1\n");
		return 0;
	}
	int re=0;
	for(int i=n;i>=1;i--)
	{
		if(a[i]<0)break;
		else re++;
	}
	int re2=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]<0)break;
		else re2++;
	}
	if(last<=re)ans--;
	if(last<=re2)ans-=2;
	printf("%d\n",ans);
	return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn=2e5+1e2;
const int INF=2e9;

int a[maxn],num[maxn],cnt=0,num1=INF,num2=INF;

int getint()
{
	char ch;int b=1;
	for(ch=getchar();ch>'9'||ch<'0';ch=getchar())if(ch=='-')b=-1;
	int num=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar())num=num*10+ch-'0';
	return num*b;
}

int main()
{
	int n=getint(),k=getint();
	int las=0,ans=0;
	for(int i=1;i<=n;i++)a[i]=getint();
	for(int i=1;i<=n;i++)
	{
		if(a[i-1]<0&&a[i]>=0)ans++;
		if(a[i-1]>=0&&a[i]<0)ans++;
		if(a[i]<0)
		{
			k--;
			if(las!=i-1||i==1)
			{
				if(i!=1)
				{
					if(las!=0)num[++cnt]=i-las-1;
					else num2=i-las-1;
				}
			}
			las=i;
		}
	}
	if(las!=n)num1=n-las;
	sort(num+1,num+cnt+1);
	for(int i=1;i<=cnt;i++)
	{
		if(k<=0)break;
		if(k>=num[i])
		{
			ans-=2;
			k-=num[i];
		}
	}
	/*printf("%d:",k);
	for(int i=1;i<=cnt;i++)printf("%d ",num[i]);
	printf("%d\n",num1);*/
	if(k>=num1)
	{
		ans--;
		k-=num1;
	}
	if(k<0)printf("-1\n");
	else printf("%d\n",max(0,ans));
	return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn=2e5+1e2;

int a[maxn],c[maxn],cnt=0;

int getint()
{
	char ch;int b=1;
	for(ch=getchar();ch>'9'||ch<'0';ch=getchar())if(ch=='-')b=-1;
	int num=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar())num=num*10+ch-'0';
	return num*b;
}

int main()
{
	int n=getint(),k=getint();
	for(int i=1;i<=n;i++)
	{
		a[i]=getint();
	}
	int have=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]<0&&have>0)
		{
			c[++cnt]=have;
			have=0;
		}
		if(a[i]>=0)have++;
	}
	if(have>0)c[++cnt]=have;
	sort(c+1,c+cnt+1);
	int ans=1,all=n,last;
	for(int i=cnt;i>=1;i--)
	{
		if(all>k)
		{
			all-=c[i];
			last=c[i];
			ans+=2;
		}
		else break;
	}
	int re=0;
	for(int i=n;i>=1;i--)
	{
		if(a[i]<0)break;
		else re++;
	}
	if(last<=re)ans--;
	printf("%d\n",ans);
	return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn=2e5+1e2;

int a[maxn],c[maxn],cnt=0;

int getint()
{
	char ch;int b=1;
	for(ch=getchar();ch>'9'||ch<'0';ch=getchar())if(ch=='-')b=-1;
	int num=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar())num=num*10+ch-'0';
	return num*b;
}

int main()
{
	int n=getint(),k=getint();
	for(int i=1;i<=n;i++)
	{
		a[i]=getint();
	}
	int have=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]<0&&have>0)
		{
			c[++cnt]=have;
			have=0;
		}
		if(a[i]>=0)have++;
	}
	if(have>0)c[++cnt]=have;
	sort(c+1,c+cnt+1);
	int ans=1,all=n,last;
	for(int i=cnt;i>=1;i--)
	{
		if(all>k)
		{
			all-=c[i];
			last=c[i];
			ans+=2;
		}
		else break;
	}
	if(all>k)
	{
		printf("-1\n");
		return 0;
	}
	int re=0;
	for(int i=n;i>=1;i--)
	{
		if(a[i]<0)break;
		else re++;
	}
	if(last<=re)ans--;
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
#define FN(i, b) for (int (i) = (0); (i) < (b) ; (i)++)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc(a) scanf("%d", &a)
using namespace std;
int n, k;
const int kMaxN = 2*1E5 + 5;
int sh[kMaxN]; // length of summer hole

int main() {
	while (sc2(n,k) == 2) {
		int sco = 0;
		int nsh = 0;
		bool is = 1;
		int nc = 0;
		int last = 0;
		FN (i, n) {
			int xx;
			sc(xx);
			sco += xx>=0;
			sh[i] = 0;
			if (i > 0 && xx >= 0 && last < 0) {
				nsh++;
			}
			if (nsh > 0 && xx >= 0) {
				sh[nsh - 1]++;
			}
			if (is != (xx >= 0)) {
				nc++;
				is = (xx >= 0);
			}
			last = xx;
		}
		bool we = 0;
		int tval;
		int rc = k - n + sco;

		if (rc < 0) {
			puts("-1");
		} else {

			if (last >= 0) {
				we = 1;
				tval = sh[nsh - 1];
				nsh--;
			}
			sort(sh, sh + nsh);
			FN (i, nsh) {
				if (sh[i] <= rc) {
					rc -= sh[i];
					nc -= 2;
				}
			}
			if (we && rc >= tval) {
				nc--;
			}
			printf("%d\n", nc);

		}
	}
}


#include<bits/stdc++.h>
#define FN(i, b) for (int (i) = (0); (i) < (b) ; (i)++)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc(a) scanf("%d", &a)
using namespace std;
int n, k;
const int kMaxN = 2*1E5 + 5;
int sh[kMaxN]; // length of summer hole

int main() {
	while (sc2(n,k) == 2) {
		int sc = 0;
		int nsh = 0;
		bool is = 1;
		int nc = 0;
		int last = 0;
		FN (i, n) {
			int xx;
			sc(xx);
			sc += xx>=0;
			sh[i] = 0;
			if (i > 0 && xx >= 0 && last < 0) {
				nsh++;
			}
			if (nsh > 0 && xx >= 0) {
				sh[nsh - 1]++;
			}
			if (is != (xx >= 0)) {
				nc++;
				is = xx >= 0;
			}
			last = xx;
		}
		bool we = 0;
		int tval;
		int rc = k - n + sc;
		if (last >= 0) {
			we = 1;
			tval = sh[nsh - 1];
			nsh--;
		}
		sort(sh, sh + nsh);
		FN (i, nsh) {
			if (sh[i] <= rc) {
				rc -= sh[i];
				nc -= 2;
			}
		}
		if (we && rc >= tval) {
			nc--;
		}
		if (rc < 0) {
			puts("-1");
		} else {
			printf("%d\n", nc);
		}

	}
}


#include<bits/stdc++.h>
#define FN(i, b) for (int (i) = (0); (i) < (b) ; (i)++)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc(a) scanf("%d", &a)
#define MAXN 2000006
using namespace std;
int n, k;
int sh[MAXN]; // length of summer hole

int main() {
	while (sc2(n,k) == 2) {
		int sco = 0;
		int nsh = 0;
		bool is = 1;
		int nc = 0;
		int last = 0;
		FN (i, n) {
			int xx;
			sc(xx);
			sco += xx>=0;
			sh[i] = 0;
			if (i > 0 && xx >= 0 && last < 0) {
				nsh++;
			}
			if (nsh > 0 && xx >= 0) {
				sh[nsh - 1]++;
			}
			if (is != (xx >= 0)) {
				nc++;
				is = (xx >= 0);
			}
			last = xx;
		}
		bool we = 0;
		int tval;
		int rc = k - n + sco;

		if (rc < 0) {
			puts("-1");
		} else {

			if (last >= 0 && nsh > 0) {
				we = 1;
				tval = sh[nsh - 1];
				nsh--;
			}
			sort(sh, sh + nsh);
			FN (i, nsh) {
				if (sh[i] <= rc) {
					rc -= sh[i];
					nc -= 2;
				}
			}
			if (we && rc >= tval) {
				nc--;
			}
			printf("%d\n", nc);

		}
	}
}


#include<bits/stdc++.h>
#define FN(i, b) for (int (i) = (0); (i) < (b) ; (i)++)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc(a) scanf("%d", &a)
using namespace std;
int n, k;
const int kMaxN = 2*1E5 + 5;
int sh[kMaxN]; // length of summer hole

int main() {
	while (sc2(n,k) == 2) {
		int sco = 0;
		int nsh = 0;
		bool is = 1;
		int nc = 0;
		int last = 0;
		FN (i, n) {
			int xx;
			sc(xx);
			sco += xx>=0;
			sh[i] = 0;
			if (i > 0 && xx >= 0 && last < 0) {
				nsh++;
			}
			if (nsh > 0 && xx >= 0) {
				sh[nsh - 1]++;
			}
			if (is != (xx >= 0)) {
				nc++;
				is = xx >= 0;
			}
			last = xx;
		}
		bool we = 0;
		int tval;
		int rc = k - n + sco;
		if (last >= 0) {
			we = 1;
			tval = sh[nsh - 1];
			nsh--;
		}
		sort(sh, sh + nsh);
		FN (i, nsh) {
			if (sh[i] <= rc) {
				rc -= sh[i];
				nc -= 2;
			}
		}
		if (we && rc >= tval) {
			nc--;
		}
		if (rc < 0) {
			puts("-1");
		} else {
			printf("%d\n", nc);
		}

	}
}


#include<bits/stdc++.h>
#define FN(i, b) for (int (i) = (0); (i) < (b) ; (i)++)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc(a) scanf("%d", &a)
using namespace std;
int n, k;
const int kMaxN = 2*1E5 + 5;
int v[kMaxN];
int sh[kMaxN]; // length of summer hole

int main() {
	while (sc2(n,k) == 2) {
		FN (i, n) {
			sc(v[i]);
		}
		int nc = 0;
		int sc = 0;
		FN (i, n) {
			sc += v[i]>=0;
			sh[i] = 0;
		}
		if (n - sc > k) {
			puts("-1");
		} else {
			int rc = k - n + sc;
			int nsh = 0;
			bool is = 1;
			FN (i, n) {
				if (i > 0 && v[i] >= 0 && v[i - 1] < 0) {
					nsh++;
				}
				if (nsh > 0 && v[i] >= 0) {
					sh[nsh - 1]++;
				}
				if (is != (v[i] >= 0)) {
					nc++;
					is = v[i] >= 0;
				}
			}
			bool we = 0;
			int tval;
			if (v[n - 1] >= 0) {
				we = 1;
				tval = sh[nsh - 1];
				nsh--;
			}
			sort(sh, sh + nsh);
			FN (i, nsh) {
				if (sh[i] <= rc) {
					rc -= sh[i];
					nc -= 2;
				}
			}
			if (we && rc >= tval) {
				nc--;
			}
			printf("%d\n", nc);
		}

	}
}


#include<bits/stdc++.h>
#define FN(i, b) for (int (i) = (0); (i) < (b) ; (i)++)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc(a) scanf("%d", &a)
#define MAXN 2000006
using namespace std;
int n, k;
int sh[MAXN]; // length of summer hole

int main() {
	while (sc2(n,k) == 2) {
		int sco = 0;
		int nsh = 0;
		bool is = 1;
		int nc = 0;
		int last = 0;
		FN (i, n) {
			int xx;
			sc(xx);
			sco += xx>=0;
			sh[i] = 0;
			if (i > 0 && xx >= 0 && last < 0) {
				nsh++;
			}
			if (nsh > 0 && xx >= 0) {
				sh[nsh - 1]++;
			}
			if (is != (xx >= 0)) {
				nc++;
				is = (xx >= 0);
			}
			last = xx;
		}
		bool we = 0;
		int tval;
		int rc = k - n + sco;

		if (rc < 0) {
			puts("-1");
		} else {

			if (last >= 0) {
				we = 1;
				tval = sh[nsh - 1];
				nsh--;
			}
			sort(sh, sh + nsh);
			FN (i, nsh) {
				if (sh[i] <= rc) {
					rc -= sh[i];
					nc -= 2;
				}
			}
			if (we && rc >= tval) {
				nc--;
			}
			printf("%d\n", nc);

		}
	}
}


#include<bits/stdc++.h>
#define FN(i, b) for (int (i) = (0); (i) < (b) ; (i)++)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc(a) scanf("%d", &a)
using namespace std;
int n, k;
const int kMaxN = 2*1E5 + 5;
int v[kMaxN];
int sh[kMaxN]; // start, length

int main() {
	while (sc2(n,k) == 2) {
		FN (i, n) {
			sc(v[i]);
		}
		int nc = 0;
		int sc = 0;
		FN (i, n) {
			sc += v[i]>=0;
			sh[i] = 0;
		}
		if (n - sc > k) {
			puts("-1");
		} else {
			int rc = k - n + sc;
			int nsh = 0;
			bool is = 1;
			FN (i, n) {
				if (i > 0 && v[i] >= 0 && v[i - 1] < 0) {
					nsh++;
				}
				if (nsh > 0 && v[i] >= 0) {
					sh[nsh - 1]++;
				}
				if (is != (v[i] >= 0)) {
					nc++;
					is = v[i] >= 0;
				}
			}
			bool we = 0;
			int tval;
			if (v[n - 1] >= 0) {
				we = 1;
				tval = sh[nsh - 1];
				nsh--;
			}
			sort(sh, sh + nsh);
			FN (i, nsh) {
				if (sh[i] <= rc) {
					rc -= sh[i];
					nc -= 2;
				}
			}
			if (we && rc >= tval) {
				nc--;
			}
			printf("%d\n", nc);
		}

	}
}


#include <cstdio>
#include <algorithm>
using namespace std;
#define N 200000 + 5
#define INF 1234567890

int n, k, ans = 0, Min, Max, A[N];

inline int Solve(int ret)
{
	if (ret < 0) return INF;
	int res = ans;
	for (int i = 1; i <= A[0]; i ++)
	{
		if (ret < A[i]) break ;
		ret -= A[i], res -= 2;
	}
	return res;
}

int main()
{
	scanf("%d%d", &n, &k);
	for (int i = 1, x, last = 0; i <= n; i ++)
	{
		scanf("%d", &x);
		if (x < 0)
		{
			if (last)
				A[++ A[0]] = i - last - 1;
			else Min = i;
			Max = i;
			last = i, ans += 2, k --;
		}
	}
	if (k < 0) puts("-1");
	eles if (ans == 0) puts("0");
	else
	{
		sort(A + 1, A + A[0] + 1);
		printf("%d\n", min(Solve(k - (n - Max)) - 1, Solve(k)));
	}
	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
#define N 200000 + 5
#define INF 1234567890

int n, k, ans = 0, Min, Max, A[N];

inline int Solve(int ret)
{
	if (ret < 0) return INF;
	int res = ans;
	for (int i = 1; i <= A[0]; i ++)
	{
		if (ret < A[i]) break ;
		ret -= A[i], res -= 2;
	}
	return res;
}

int main()
{
	scanf("%d%d", &n, &k);
	for (int i = 1, x, last = 0; i <= n; i ++)
	{
		scanf("%d", &x);
		if (x < 0)
		{
			if (last)
				A[++ A[0]] = i - last - 1;
			else Min = i;
			Max = i;
			last = i, ans += 2, k --;
		}
	}
	if (k < 0) puts("-1");
	else
	{
		sort(A + 1, A + A[0] + 1);
		printf("%d\n", min(Solve(k - (n - Max)) - 1, Solve(k)));
	}
	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
#define N 200000 + 5
#define INF 1234567890

int n, k, ans = 1, Min, Max, A[N];

inline int Solve(int ret)
{
	if (ret < 0) return INF;
	int res = ans;
	for (int i = 1; i <= A[0]; i ++)
	{
		if (ret < A[i]) break ;
		ret -= A[i], res -= 2;
	}
	return res;
}

int main()
{
	scanf("%d%d", &n, &k);
	for (int i = 1, x, last = 0; i <= n; i ++)
	{
		scanf("%d", &x);
		if (x < 0)
		{
			if (last)
				A[++ A[0]] = i - last - 1;
			else Min = i;
			Max = i;
			last = i, ans += 2, k --;
		}
	}
	if (k < 0) puts("-1");
	else
	{
		sort(A + 1, A + A[0] + 1);
		printf("%d\n", min(min(Solve(k - (Min - 1)) - 1, Solve(k - (n - Max)) - 1), min(Solve(k), Solve(k - (Min - 1) - (n - Max)) - 2)));
	}
	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
#define N 200000 + 5
#define INF 1234567890

int n, k, ans = 0, Min, Max, A[N];

inline int Solve(int ret)
{
	if (ret < 0) return INF;
	int res = ans;
	for (int i = 1; i <= A[0]; i ++)
	{
		if (ret < A[i]) break ;
		ret -= A[i], res -= 2;
	}
	return res;
}

int main()
{
	scanf("%d%d", &n, &k);
	for (int i = 1, x, last = 0; i <= n; i ++)
	{
		scanf("%d", &x);
		if (x < 0)
		{
			if (last)
				A[++ A[0]] = i - last - 1;
			else Min = i;
			Max = i;
			last = i, ans += 2, k --;
		}
	}
	if (k < 0) puts("-1");
	else if (ans == 0) puts("0");
	else
	{
		sort(A + 1, A + A[0] + 1);
		printf("%d\n", min(Solve(k - (n - Max)) - 1, Solve(k)));
	}
	return 0;
}


#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define pii pair<long long,long long>
#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define PI 3.14159265
#define ll long long
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define debug(x) cout << #x << " = " << x << endl
#define INF 1000000009
#define mod 1000000007
vector<pair<ll int,ll int> >p;
bool compare(pair<ll int,ll int>p1,pair<ll int,ll int>p2)
{
    if(p1.second==p2.second)
    return p1.first<p2.first;
    else
     return p1.second<p2.second;

}
int main()
{
ll int n,k;
cin>>n>>k;
ll int arr[n];
ll int count=0;
ll int prev =-1;
for(int i=0;i<n;i++)
{
    cin>>arr[i];
    if(arr[i]<0)
    {count++;
    prev = i;
    }
}

if(count>k)
{
    cout<<-1;
    return 0;
}

if(count==0)
{cout<<0;
return 0;
}

ll int r=0;
ll int m=0;
ll int ans=0;
for(int i=0;i<n;i++)
{
    if(arr[i]<0)
    {
        ans++;

        while(i<n && arr[i]<0)
        {
            i++;
        }
        if(i<n)
        {
            ans++;
            r=0;
            m = i;

            while(arr[i]>=0 && i<n)
            {
                i++;
                r++;
            }
            i--;
            if(r>0)
           p.push_back(make_pair(m,r));

        }

    }
}
//cout<<ans;
 k  = k -count;
 ll int a=-1;
// cout<<k<<" "<<ans<<"\n";
sort(p.begin(),p.end(),compare);
 m  = p.size();
 /*for(int i=0;i<m;i++)
    {
       cout<<p[i].first<<" "<<p[i].second<<" "<<prev<<"\n";
 }*/
  for(int i=0;i<m;i++)
  {

     if(k==0)
     break;
     if(p[i].second<=k)
     {
         if(p[i].first<prev)
         {

         k = k - p[i].second;
           ans-=2;        // cout<<k<<" ";
         }
         else
         {
             a = i;
         }
     }
     else
     {
         break;
     }
    // cout<<k<<"\n";
 }
 if(a!=-1)
 {
 if(p[a].second<=k)
 {
     ans--;
 }
 }
 cout<<ans<<"\n";

    return 0;
}


#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define pii pair<long long,long long>
#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define PI 3.14159265
#define ll long long
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define debug(x) cout << #x << " = " << x << endl
#define INF 1000000009
#define mod 1000000007
vector<pair<ll int,ll int> >p;
bool compare(pair<ll int,ll int>p1,pair<ll int,ll int>p2)
{
    if(p1.second==p2.second)
    return p1.first<p2.first;
    return p1.second<p2.second;

}
int main()
{
ll int n,k;
cin>>n>>k;
ll int arr[n];
ll int count=0;
ll int prev =0;
for(int i=0;i<n;i++)
{
    cin>>arr[i];
    if(arr[i]<0)
    {count++;
    prev = i;
    }
}

if(count>k)
{
    cout<<-1;
    return 0;
}

if(count==0)
{cout<<0;
return 0;
}

ll int r=0;
ll int m=0;
ll int ans=0;
for(int i=0;i<n;i++)
{
    if(arr[i]<0)
    {
        ans++;

        while(i<n && arr[i]<0)
        {
            i++;
        }
        if(i<n)
        {
            ans++;
            r=0;
            m = i;

            while(arr[i]>=0 && i<n)
            {
                i++;
                r++;
            }
            i--;
           p.push_back(make_pair(m,r));

        }

    }
}
//cout<<ans;
 k  = k -count;
// cout<<k<<" "<<ans<<"\n";
sort(p.begin(),p.end(),compare);
 m  = p.size();
 /*for(int i=0;i<m;i++)
 {
     cout<<p[i].first<<" "<<p[i].second<<"\n";
 }*/
 for(int i=0;i<m;i++)
 {
     if(p[i].second<=k)
     {
         if(p[i].first<prev)
         {

         k = k - p[i].second;
           ans-=2;        // cout<<k<<" ";
         }
         else
         {ans--;
         k  =  k - p[i].second;
         }
     }
     else
     {
         break;
     }
 }
 cout<<ans<<"\n";

    return 0;
}


#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define pii pair<long long,long long>
#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define PI 3.14159265
#define ll long long
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define debug(x) cout << #x << " = " << x << endl
#define INF 1000000009
#define mod 1000000007

int main()
{

ll int n,k;
cin>>n>>k;
ll int arr[n];
ll int count=0;
for(int i=0;i<n;i++)
{
    cin>>arr[i];

    if(arr[i]<0)
    {
        count++;
    }
}
if(count>k)
{
    cout<<"-1";
    return 0;
}
ll int pos[count];
ll int count1;
ll int m=0;
ll int prev=-1;
for(int i=0;i<n;i++)
{

    if(arr[i]<0 && prev!=-1)
    { pos[m] = i-prev;
      m++;

    }
    if(arr[i]<0)
    {
        prev  = i;
    }
}

ll int ans=0;
ll int curr=0;

ll int flag=1;

for(int i=0;i<prev;i++)
{
    if(arr[i]>0)
    continue;
    else
    {  if(flag==1)
        {

            ans+=1;

          flag=0;
           k =k-1;

        }

       // cout<<curr<<"\n";
         if(pos[curr] +  count-curr-2 <=k)
        {
           // cout<<ans<<"ffff"<<"\n";
             k = k - pos[curr];

             i+=pos[curr]-1;
             curr++;
             //cout<<i<<"\n";
             //cout<<k<<"\n";
        }
        else
        {
            ans+=1;
            flag=1;
            curr++;
            curr++;
            curr--;
           // cout<<"fff";

        }
       // cout<<ans<<"\n";
    }
}

if(flag==1)
{ans+=1;
k = k-1;
}
if(k>=n-1-prev)
cout<<ans<<"\n";
else
cout<<ans+1<<"\n";

    return 0;
}


#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define pii pair<long long,long long>
#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define PI 3.14159265
#define ll long long
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define debug(x) cout << #x << " = " << x << endl
#define INF 1000000009
#define mod 1000000007

int main()
{

ll int n,k;
cin>>n>>k;
ll int arr[n];
ll int count=0;
for(int i=0;i<n;i++)
{
    cin>>arr[i];

    if(arr[i]<0)
    {
        count++;
    }
}
if(count>k)
{
    cout<<"-1";
    return 0;
}
ll int pos[count];
ll int count1;
ll int m=0;
ll int prev=-1;
for(int i=0;i<n;i++)
{

    if(arr[i]<0 && prev!=-1)
    { pos[m] = i-prev;
      m++;

    }
    if(arr[i]<0)
    {
        prev  = i;
    }
}

ll int ans=0;
ll int curr=0;

ll int flag=1;

for(int i=0;i<prev;i++)
{
    if(arr[i]<0)

    {  if(flag==1)
        {

            ans+=1;
            flag=0;
            k =k-1;

        }

       // cout<<curr<<"\n";
         if(pos[curr] + count-curr-2 <=k)
        {
           // cout<<ans<<"ffff"<<"\n";
             k = k - pos[curr];
             //cout<<i<<"\n";
            i= i + pos[curr]-1;
             curr++;
             //cout<<i<<"\n";
             //cout<<k<<"\n";
        }
        else
        {
            ans+=1;
            flag=1;
            curr++;
            curr++;
            curr--;
           // cout<<"fff";

        }
       //cout<<ans<<"\n";
    }
}

if(flag==1)
{ans+=1;
k = k-1;
}
if(k>=n-1-prev)
cout<<ans<<"\n";
else
cout<<ans+1<<"\n";

    return 0;
}