//
//  main.cpp
//  Tests
//
//  Created by Pâris on 20/11/2013.
//  Copyright (c) 2013 Pâris. All rights reserved.
//
#include<stdio.h>
#include<stdlib.h>

int croissance(int* deltas, int len)
{
    int i = 0;
    for(i;i<len - 1;i++)
    {
        if(deltas[i]>deltas[i + 1] + 1)
            return 0;
    }
    if(deltas[len - 1]>deltas[0] + 1)
        return 0;
    return 1;
}

int is_number(char c){
    return c <= '9' && c >= '0';
}

int* read_deltas(int len){
    int *result = (int*)malloc( len * sizeof(int));
    
    {
        int index;
        for (index = 0 ; index < len; index++)
        {
            int num = 0;
            char current_char = '\000';
            scanf("%c", &current_char);
            int ok = is_number(current_char);
            while (ok)
            {
                num = num * 10 + current_char - '0';
                scanf("%c", &current_char);
                ok = is_number(current_char);
            }
            result[index] = num;
        }
    }
    return result;
}

int main(void){
    int len = 0, res;
    scanf("%d", &len);
    scanf("%*[ \t\r\n]c", 0);
    int* deltas = read_deltas(len);
    res = croissance(deltas, len);
    printf("%d",res);
    return 0;
}