import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.math;

long n, m;

void main() {
    scan(n, m);

    auto cmb = new long[][](n + 1, n + 1);
    auto dp = new long[][](n + 1, n + 1);
    foreach (i ; 0 .. n + 1) {
        cmb[i][0] = cmb[i][i] = 1;
        dp[i][0] = dp[i][i] = 1;
    }
    foreach (i ; 0 .. n + 1) {
        foreach (j ; 1 .. i) {
            cmb[i][j] = (cmb[i-1][j] + cmb[i-1][j-1]);
            if (cmb[i][j] >= m) cmb[i][j] -= m;
            dp[i][j] = (dp[i-1][j-1] + (j + 1) * dp[i-1][j] % m);
            if (dp[i][j] >= m) dp[i][j] -= m;
        }
    }

    debug {
        //writeln(cmb);
        //writeln(dp);
    }

    auto tpm = new long[](n*n + 1);
    auto tpm1 = new long[](n*n + 1);
    tpm[0] = tpm1[0] = 1;
    foreach (i ; 1 .. n*n + 1) {
        tpm[i] = tpm[i-1] * 2 % m;
        tpm1[i] = tpm1[i-1] * 2 % (m-1);
    }

    long f(int k) {
        long res;
        auto t = powmod(2, tpm1[n - k], m);

        foreach (x ; 0 .. k + 1) {
            //res += powmod(2, powmod(2, n - k, m - 1), m) * dp[k][x] % m * powmod(2, (n - k) * x, m) % m;
            res += t * dp[k][x] % m * tpm[(n-k)*x] % m;
            if (res >= m) res -= m;
        }

        return res;
    }

    long ans;

    foreach (int k ; 0 .. n.to!int + 1) {
        if (k & 1) {
            ans -= cmb[n][k] * f(k) % m;
            if (ans < 0) ans += m;
        }
        else {
            ans += cmb[n][k] * f(k) % m;
            if (ans >= m) ans -= m;
        }
    }

    writeln(ans);
}



// x^y % mod
long powmod(long x, long y, long mod) {
    return y > 0 ? powmod(x, y>>1, mod)^^2 % mod * x^^(y&1) % mod : 1L;
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}