Problem:
Score : 300 points

Problem Statement

There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step.
He can climb up one or two steps at a time.

However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps.

How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps?
Find the count modulo 1\ 000\ 000\ 007.

Constraints

1 \leq N \leq 10^5

0 \leq M \leq N-1

1 \leq a_1 < a_2 < ... < a_M \leq N-1

Input

Input is given from Standard Input in the following format:

N M
a_1
a_2
.
.
.
a_M

Output

Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007.

Sample Input 1

6 1
3

Sample Output 1

4

There are four ways to climb up the stairs, as follows:

0 \to 1 \to 2 \to 4 \to 5 \to 6

0 \to 1 \to 2 \to 4 \to 6

0 \to 2 \to 4 \to 5 \to 6

0 \to 2 \to 4 \to 6

Sample Input 2

10 2
4
5

Sample Output 2

0

There may be no way to climb up the stairs without setting foot on the broken steps.

Sample Input 3

100 5
1
23
45
67
89

Sample Output 3

608200469

Be sure to print the count modulo 1\ 000\ 000\ 007.

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Runtime Error)

import java.io.*;
import java.util.*;


public class Main {

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        InputReader.OutputWriter out = new InputReader.OutputWriter(outputStream);


        int n = in.nextInt();
        int m = in.nextInt();
        int mod = 1_000_000_000 + 7;
        int [] a = new int[n];
        for (int i = 0; i < m; i++) {
            a[in.nextInt() - 1] = 1;
        }
        int [] dp = new int[n];
        if(a[0] == 1) {
            dp[1] = 1;
        }
        else {
            if(a[1] == 1) dp[1] = 0;
            else {
                dp[0] = 1;
                dp[1] = 2;
            }
        }
        for (int i = 2; i < n; i++) {
            dp[i] = (dp[i-1] + dp[i-2])%mod;
            if (a[i] == 1) {
                dp[i] = 0;
            }
        }
        out.println(dp[n-1]);
        out.flush();
    }
    private static int bfs(char[][] c, int i, int j,int length,boolean[][] visited) {
        LinkedList<Point> q = new LinkedList<>();
        q.add(new Point(i,j));
        int distance = 0;
        while (!q.isEmpty()) {
            int size = q.size();
            for (int k = 0; k < size; k++) {
                Point current = q.pollFirst();
                visited[current.getI()][current.getJ()] = true;
                int up = current.getI() - 1;
                if (up >=0) {
                    if(!visited[up][current.getJ()]) {
                        if(c[up][current.getJ()] == 'Y') return distance + 1;
                        else q.add(new Point(up,current.getJ()));
                    }
                }
                int down = current.getI() + 1;
                if (down<c.length) {
                    if(!visited[down][current.getJ()]) {
                        if (c[down][current.getJ()] == 'Y') return distance + 1;
                        else q.add(new Point(down, current.getJ()));
                    }
                }
                int left = current.getJ() - 1;
                if (left>=0) {
                    if(!visited[current.getI()][left]) {
                        if (c[current.getI()][left] == 'Y') return distance + 1;
                        else q.add(new Point(current.getI(), left));
                    }
                }
                int right = current.getJ() + 1;
                if(right<c[i].length) {
                    if(!visited[current.getI()][right]) {
                        if (c[current.getI()][right] == 'Y') return distance + 1;
                        else q.add(new Point(current.getI(), right));
                    }
                }
            }
            distance++;
        }
        return Integer.MAX_VALUE;
    }


}
class Point {
    private int i;
    private int j;

    public int getI() {
        return i;
    }

    public int getJ() {
        return j;
    }
    public Point(int i, int j) {
        this.i = i;
        this.j = j;
    }
}


class InputReader extends BufferedReader {
    StringTokenizer tokenizer;

    public InputReader(InputStream inputStream) {
        super(new InputStreamReader(inputStream), 32768);
    }

    public InputReader(String filename) {
        super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return tokenizer.nextToken();
    }

    public Integer nextInt() {
        return Integer.valueOf(next());
    }
    public Long nextLong() {return  Long.valueOf(next());}

    static class OutputWriter extends PrintWriter {
        public OutputWriter(OutputStream outputStream) {
            super(outputStream);
        }

        public OutputWriter(Writer writer) {
            super(writer);
        }

        public OutputWriter(String filename) throws FileNotFoundException {
            super(filename);
        }

        public void close() {
            super.close();
        }
    }
}