#include <cstdio>
typedef long long ll;
const int N_LIMIT = 1000010;

bool exists[N_LIMIT];
int judge_data[N_LIMIT];
int n;
ll x;

long long calculateWater(){
    long long all_water = 0;

    // Calculate water from left.
    int last_height = 0;
    for(int i=1; i<=n; ++i){
        if(judge_data[i]==n) break;
        if(last_height >= judge_data[i]){
            all_water += last_height - judge_data[i];
        } else {
            last_height = judge_data[i];
        }
    }

    // Calculate water from right.
    last_height = 0;
    for(int i=n; i>=1; --i){
        if(judge_data[i]==n) break;
        if(last_height >= judge_data[i]){
            all_water += last_height - judge_data[i];
        } else {
            last_height = judge_data[i];
        }
    }
    return all_water;
}

int main()
{
    FILE *input = fopen("/var/www/bbs/prob/1419/input.txt","r");
    fscanf(input, "%d%lld",&n,&x);
    fclose(input);

    FILE *output = fopen("/var/www/bbs/prob/1419/input2.txt","r");
    int sol;
    fscanf(output, "%d",&sol);
    fclose(output);

    FILE *judging = fopen("/var/www/bbs/prob/1419/output.txt","r");
    if(sol == -1){
        int contestant_sol;
        if(fscanf(judging,"%d",&contestant_sol) != 1) goto WA;
        if(contestant_sol!=-1) goto WA;
        goto Accepted;
    }
    int i, buf;
    for(i=1; i<=n; ++i){
        // WA 1; Not enough inputs
        if(fscanf(judging,"%d",&buf) != 1){
            fclose(judging);
            goto WA;
        }
        // WA 2; Invalid Data Range
        if(buf<1 || buf>n) {
            fclose(judging);
            goto WA;
        }
        exists[buf]   = true;
        judge_data[i] = buf;
    }
    fclose(judging);

    // Check if everything exists.
    // WA 3; Output isn't a permutation
    for(i=1; i<=n; ++i) {
        if(!exists[buf]) {
            goto WA;
        }
    }

    if(calculateWater() != x){
        // WA 4; Water amount does not match X
        goto WA;
    }

Accepted:
    puts("1");
    return 0;
WA:
    puts("0");
    return 0;
}
