// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#define dibs reserve
#define OVER9000 1234567890
#define tisic 47
#define soclose 10e-7
#define M 1000000007
#define add(x,y) {x =(x+y)%M; if(x < 0) x +=M;}
// mylittlepony
using namespace std;
int main() {
int N;
cin >> N;
vector<int> V(N);
for(int i =0; i < N; i++) cin >> V[i];
if(V[0] > 0 || V[N-1] > 0) {
cout << "0\n";
return 0;}
V[0] =V[N-1] =0;
vector<long long> W(tisic,0);
W[0] =1;
for(int i =0; i < N; i++) {
if(2*i <= N) W.push_back(0);
if(V[i] == -1) {
int a =W[0], b =W[1];
add(W[0],W[1]);
for(int j =1; j <= W.size()-1; j++) {
add(W[j],a+W[j+1]);
a =b;
b =W[j+1];}}
else {
if(V[i] > i) {cout << "0\n"; return 0;}
add(W[V[i]],W[V[i]+1]);
if(V[i] > 0) add(W[V[i]],W[V[i]-1]);
for(int j =0; j <= W.size()-1; j++) if(j != V[i]) W[j] =0;}
}
cout << W[0] << endl;
return 0;}
// look at my code
// my code is amazing
Ly8gaW9zdHJlYW0gaXMgdG9vIG1haW5zdHJlYW0KI2luY2x1ZGUgPGNzdGRpbz4KLy8gYml0Y2ggcGxlYXNlCiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPHF1ZXVlPgojaW5jbHVkZSA8c3RhY2s+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNkZWZpbmUgZGlicyByZXNlcnZlCiNkZWZpbmUgT1ZFUjkwMDAgMTIzNDU2Nzg5MAojZGVmaW5lIHRpc2ljIDQ3CiNkZWZpbmUgc29jbG9zZSAxMGUtNwojZGVmaW5lIE0gMTAwMDAwMDAwNwojZGVmaW5lIGFkZCh4LHkpIHt4ID0oeCt5KSVNOyBpZih4IDwgMCkgeCArPU07fQovLyBteWxpdHRsZXBvbnkKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewogICAgaW50IE47CiAgICBjaW4gPj4gTjsKICAgIHZlY3RvcjxpbnQ+IFYoTik7CiAgICBmb3IoaW50IGkgPTA7IGkgPCBOOyBpKyspIGNpbiA+PiBWW2ldOwogICAgaWYoVlswXSA+IDAgfHwgVltOLTFdID4gMCkgewogICAgICAgIGNvdXQgPDwgIjBcbiI7CiAgICAgICAgcmV0dXJuIDA7fQogICAgVlswXSA9VltOLTFdID0wOwogICAgCiAgICB2ZWN0b3I8bG9uZyBsb25nPiBXKHRpc2ljLDApOwogICAgV1swXSA9MTsKICAgIGZvcihpbnQgaSA9MDsgaSA8IE47IGkrKykgewogICAgICAgIGlmKDIqaSA8PSBOKSBXLnB1c2hfYmFjaygwKTsKICAgICAgICBpZihWW2ldID09IC0xKSB7CiAgICAgICAgICAgIGludCBhID1XWzBdLCBiID1XWzFdOwogICAgICAgICAgICBhZGQoV1swXSxXWzFdKTsKICAgICAgICAgICAgZm9yKGludCBqID0xOyBqIDw9IFcuc2l6ZSgpLTE7IGorKykgewogICAgICAgICAgICAgICAgYWRkKFdbal0sYStXW2orMV0pOwogICAgICAgICAgICAgICAgYSA9YjsKICAgICAgICAgICAgICAgIGIgPVdbaisxXTt9fQogICAgICAgIGVsc2UgewogICAgICAgICAgICBpZihWW2ldID4gaSkge2NvdXQgPDwgIjBcbiI7IHJldHVybiAwO30KICAgICAgICAgICAgYWRkKFdbVltpXV0sV1tWW2ldKzFdKTsKICAgICAgICAgICAgaWYoVltpXSA+IDApIGFkZChXW1ZbaV1dLFdbVltpXS0xXSk7CiAgICAgICAgICAgIGZvcihpbnQgaiA9MDsgaiA8PSBXLnNpemUoKS0xOyBqKyspIGlmKGogIT0gVltpXSkgV1tqXSA9MDt9CiAgICAgICAgfQogICAgY291dCA8PCBXWzBdIDw8IGVuZGw7CiAgICByZXR1cm4gMDt9CiAKLy8gbG9vayBhdCBteSBjb2RlCi8vIG15IGNvZGUgaXMgYW1hemluZw==