#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#define maxsize 100
using namespace std;
int match(char A[],int n)
{
char stack[maxsize];
int count=0,top=-1,i;
for(i=0;i<n;i++)
{
if(A[i]=='(') stack[++top];
if(A[i]==')')
{
if(top==-1) return 0;
else --top;
}
}
if(top==-1) return 1;
else return 0;
if(count==0) return 1;
else return 0;
}
int main()
{
char A[maxsize];
int n,i;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&A[i]);
printf("%d\n",match(A,n));
return 0;
}