Problem: In "Takahashi-ya", a ramen restaurant, basically they have one menu: "ramen", but N kinds of toppings are also offered. When a customer orders a bowl of ramen, for each kind of topping, he/she can choose whether to put it on top of his/her ramen or not. There is no limit on the number of toppings, and it is allowed to have all kinds of toppings or no topping at all. That is, considering the combination of the toppings, 2^N types of ramen can be ordered.

Akaki entered Takahashi-ya. She is thinking of ordering some bowls of ramen that satisfy both of the following two conditions:

* Do not order multiple bowls of ramen with the exactly same set of toppings.
* Each of the N kinds of toppings is on two or more bowls of ramen ordered.



You are given N and a prime number M. Find the number of the sets of bowls of ramen that satisfy these conditions, disregarding order, modulo M. Since she is in extreme hunger, ordering any number of bowls of ramen is fine.

Constraints

* 2 \leq N \leq 3000
* 10^8 \leq M \leq 10^9 + 9
* N is an integer.
* M is a prime number.

Input

Input is given from Standard Input in the following format:


N M


Output

Print the number of the sets of bowls of ramen that satisfy the conditions, disregarding order, modulo M.

Examples

Input

2 1000000007


Output

2


Input

3 1000000009


Output

118


Input

50 111111113


Output

1456748


Input

3000 123456791


Output

16369789

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;

public class Main {
    FastScanner in;
    PrintWriter out;

    int mod;

    int add(int x, int y) {
        x += y;
        return x < mod ? x : (x - mod);
    }

    int sub(int x, int y) {
        x -= y;
        return x < 0 ? (x + mod) : x;
    }

    int mul(int x, int y) {
        return (int) (x * 1L * y % mod);
    }

    int[] pow2;
    int[] pow22;
    int[][] c;

    int pow(int x, int y) {
        int res = 1;
        for (int i = 31; i >= 0; i--) {
            res = mul(res, res);
            if (((1 << i) & y) != 0) {
                res = mul(res, x);
            }
        }
        return res;
    }

    int countWays(int totalLen, int failCnt, int groupsPrec) {
        int res = c[totalLen][failCnt];
        res = mul(res, pow22[totalLen - failCnt]);
        res = mul(res, groupsPrec);
        if (failCnt % 2 == 1) {
            res = sub(0, res);
        }
        return res;
    }

    void solve() {
        int n = in.nextInt();
        mod = in.nextInt();
        pow22 = new int[n + 1];
        pow22[0] = 2;
        int cc = 1;
        for (int l = 1; l <= n; l++) {
            cc = (cc + cc) % (mod - 1);
            pow22[l] = pow(2, cc);
        }
        pow2 = new int[n + 1];
        c = new int[n + 1][n + 1];
        c[0][0] = 1;
        for (int i = 1; i < c.length; i++) {
            c[i][0] = 1;
            for (int j = 1; j < c[i].length; j++) {
                c[i][j] = add(c[i - 1][j - 1], c[i - 1][j]);
            }
        }
        pow2[0] = 1;
        for (int i = 1; i < pow2.length; i++) {
            pow2[i] = add(pow2[i - 1], pow2[i - 1]);
        }
        int[] groups = new int[n + 1];
        int[] nextGroups = new int[n + 1];
        groups[0] = 1;
        int res = 0;
        res = add(res, countWays(n, 0, 1));
        for (int totalLen = 1; totalLen <= n; totalLen++) {
            Arrays.fill(nextGroups, 0);
            for (int curGroups = 0; curGroups < totalLen; curGroups++) {
                int cur = groups[curGroups];
                if (cur == 0) {
                    continue;
                }
                nextGroups[curGroups + 1] = add(nextGroups[curGroups + 1], cur);
                nextGroups[curGroups] = add(nextGroups[curGroups], mul(cur, curGroups + 1));
            }
            int[] tmp = groups;
            groups = nextGroups;
            nextGroups = tmp;
            int groupPrec = 1;
            for (int gr = 0; gr <= totalLen; gr++) {
                res = add(res, mul(groups[gr], countWays(n, totalLen, groupPrec)));
                groupPrec = mul(groupPrec, pow2[n - totalLen]);
            }
        }
        out.println(res);
    }

    void run() {
        try {
            in = new FastScanner(new File("Main.in"));
            out = new PrintWriter(new File("Main.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        new Main().runIO();
    }
}