codeparrot/codecomplex huggingface dataset:
// Problem: 1515_E. Phoenix and Computers
// Time complexity: cubic
//make sure to make new file!
import java.io.*;
import java.util.*;

public class EG14{

   public static long MOD;
   public static int MAX = 405;
   
   public static long[] fac;
   public static long[] ifac;
   
   public static void main(String[] args)throws IOException{
      BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
      PrintWriter out = new PrintWriter(System.out);
      
      StringTokenizer st = new StringTokenizer(f.readLine());
      
      int n = Integer.parseInt(st.nextToken());
      MOD = Long.parseLong(st.nextToken());
      
      long[] pow2 = new long[MAX];
      pow2[0] = 1L;
      for(int k = 1; k < MAX; k++){
         pow2[k] = (2L*pow2[k-1] + MOD)%MOD;
      }
      
      fac = new long[MAX];
      ifac = new long[MAX];
      fac[0] = 1L;
      ifac[0] = 1L;
      for(int k = 1; k < MAX; k++){
         fac[k] = ((long)k*fac[k-1] + MOD)%MOD;
         ifac[k] = modInverse(fac[k],MOD);
      }
      
      long[][] dp = new long[n][n+1];                 //what n you're on, what how many computers you've turned on manually
      
      //initial
      for(int k = 0; k < n; k++){
         dp[k][k+1] = pow2[k];
      }
      
      for(int k = 2; k < n; k++){
         for(int j = 1; j <= n; j++){
            if(dp[k-2][j-1] == 0) continue;
            long start = dp[k-2][j-1];                //number for part up to previous block
            
            for(int add = 1; ; add++){
               if(k+add-1 >= n || j+add-1 > n) break;
               
               long adder = (start * pow2[add-1] + MOD)%MOD;
               adder = (adder * choose(j+add-1,j-1) + MOD)%MOD;
               dp[k+add-1][j+add-1] = (dp[k+add-1][j+add-1] + adder + MOD)%MOD;
            }
         }
      }
      
      long answer = 0L;
      for(int k = 1; k <= n; k++){
         answer = (answer + dp[n-1][k] + MOD)%MOD;
      }
      out.println(answer);
      
      
      
      
      
      
      
      
      out.close();
   }
   
   //a choose b
   public static long choose(int a, int b){
      long prod = (fac[a]*ifac[b] + MOD)%MOD;
      return (prod*ifac[a-b] + MOD)%MOD;
   }
   
      //from geeksforgeeks
   public static long modInverse(long a, long m) 
   { 
       long m0 = m; 
       long y = 0L;
       long x = 1L; 
     
       if (m == 1L) 
         return 0L; 
     
       while (a > 1L) 
       { 
           // q is quotient 
           long q = a / m; 
           long t = m; 
     
           // m is remainder now, process same as 
           // Euclid's algo 
           m = a % m;
           a = t; 
           t = y; 
     
           // Update y and x 
           y = x - q * y; 
           x = t; 
       } 
     
       // Make x positive 
       if (x < 0L) 
          x += m0; 
     
       return x; 
   } 
      
}
// Problem: 1515_E. Phoenix and Computers
// Time complexity: cubic
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    static BufferedReader reader;
    static StringTokenizer st;
    private static void setReader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
    }
    private static void updateST() throws IOException {
        if (st==null || !st.hasMoreElements()) st = new StringTokenizer(reader.readLine());
    }
    private static int nextInt() throws IOException {
        updateST();
        return Integer.parseInt(st.nextToken());
    }

    public static void main(String[] args) throws IOException {
        setReader();
        int n = nextInt(), MOD = nextInt();
        long[] pow = new long[n+2];
        pow[0] = 1;
        for (int i=1; i<=n+1; i++) pow[i] = (pow[i-1] * 2) % MOD;
        long[][] C = new long[n+2][n+2];
        for (int i=0; i<=n+1; i++) {
            C[i][0] = 1;
            for (int j=1; j<=i; j++) {
                C[i][j] = (C[i-1][j-1] + C[i-1][j]) % MOD;
            }
        }
        long[][] dp = new long[n+2][n+1];
        dp[0][0] = 1;
        for (int i=0; i<=n; i++) {
            for (int j=0; j<=i; j++) {
                for (int k=1; i + k + 1 <= n + 1; k++) {
                    dp[i + k + 1][j + k]+=(((dp[i][j] * C[j + k][k]) % MOD * pow[k-1]) % MOD);
                    dp[i + k + 1][j + k]%=MOD;
                }
            }
        }
        long res = 0;
        for (int i=0; i<=n; i++) res = (res + dp[n+1][i]) % MOD;
        System.out.println(res);
    }
}
// Problem: 1515_E. Phoenix and Computers
// Time complexity: cubic


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class phoenix_and_computers {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] st = br.readLine().split(" ");
		int n = Integer.parseInt(st[0]);
		int m = Integer.parseInt(st[1]);

		long[][] ncr = ncrcoll(405, 405, m);
		int[] p2 = new int[n + 1];
		p2[0] = 1;
		for (int i = 1; i < p2.length; i++) {
			p2[i] = 2 * p2[i - 1] % m;
		}

		long[][] dp = new long[405][405];
		dp[0][0] = 1;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j <= i; j++) {
				for (int k = 1; i + k <= n; k++) {
					dp[i + k + 1][j + k] += ((dp[i][j] * p2[k - 1]) % m * ncr[j + k][k]);
					dp[i + k + 1][j + k] %= m;
				}
			}
		}

		long ans = 0;
		for (int i = 0; i <= n; i++) {
			ans = (ans + dp[n + 1][i]) % m;
		}

		System.out.println(ans);
	}

	static long[][] ncrcoll(int n, int k, int p) {
		long[][] arr = new long[n + 1][k + 1];
		for (int i = 1; i < arr.length; i++) {
			arr[i][0] = 1;
		}
		for (int i = 1; i < arr.length; i++) {
			for (int j = 1; j <= i && j < arr[0].length; j++) {
				if (i == 1 && j == 1) {
					arr[i][j] = 1;
				} else {
					arr[i][j] = (arr[i - 1][j] + arr[i - 1][j - 1]) % (p);
				}
			}
		}
		return arr;
	}

	public static long xpown(long x, long n) {
		long res = 1;
		while (n > 0) {
			if (n % 2 != 0) {
				res = (res * x) % 1000000007;
				n--;
			} else {
				x = (x * x) % 1000000007;
				n = n / 2;
			}
		}
		return res;
	}
}
// Problem: 1515_E. Phoenix and Computers
// Time complexity: cubic
/*
bts songs to dance to:
I need U
Run
ON
Filter
I'm fine
 */
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import static java.lang.System.out;
import java.util.*;
import java.io.*;
import java.math.*;

public class x1515E
{
    static long MOD;
    public static void main(String hi[]) throws Exception
    {
        BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(infile.readLine());
        int N = Integer.parseInt(st.nextToken());
        MOD = Long.parseLong(st.nextToken());
        fac = new long[401];
        invfac = new long[401];
        fac[0] = invfac[0] = 1L;
        for(int i=1; i <= 400; i++)
        {
            fac[i] = (fac[i-1]*i)%MOD;
            invfac[i] = power(fac[i], MOD-2, MOD);
        }
        long[] pow2 = new long[401];
        for(int i=0; i <= 400; i++)
            pow2[i] = power(2, i, MOD);
        long[][] dp = new long[N+1][N+1];
        for(int v=1; v <= N; v++)
        {
            dp[v][v] = pow2[v-1];
            for(int k=1; k <= v; k++)
                for(int block=1; block <= k; block++)
                {
                    if(block == v)
                        continue;
                    long temp = (dp[v-block-1][k-block]*calc(k-block, block))%MOD;
                    temp = (temp*pow2[block-1])%MOD;
                    dp[v][k] += temp;
                    if(dp[v][k] >= MOD)
                        dp[v][k] -= MOD;
                }
        }
        long res = 0L;
        for(int v=1; v <= N; v++)
        {
            res += dp[N][v];
            if(res >= MOD)
                res -= MOD;
        }
        System.out.println(res);
    }
    static long[] fac, invfac;
    public static long calc(int a, int b)
    {
        long res = (fac[a+b]*invfac[a])%MOD;
        return (res*invfac[b])%MOD;
    }
    public static long power(long x, long y, long p)
    {
        //0^0 = 1
        long res = 1L;
        x = x%p;
        while(y > 0)
        {
            if((y&1)==1)
                res = (res*x)%p;
            y >>= 1;
            x = (x*x)%p;
        }
        return res;
    }
}
// Problem: 1515_E. Phoenix and Computers
// Time complexity: cubic
import java.io.*;

public class E14G {
    static int[][] choose;
    public static void main(String[] args) throws IOException {
        init_io();
        int N = nint(), M = nint();
        choose = new int[N+1][];
        long[] ways = new long[N+1];
        ways[0] = 1; ways[1] = 1;
        for (int i = 0; i <= N; i++) choose[i] = new int[i+1];
        for (int i = 0; i <= N; i++) {
            choose[i][0] = choose[i][i] = 1;
            for (int j = 1; j < i; j++) {
                choose[i][j] = (choose[i-1][j-1] + choose[i-1][j]) % M;
            }
        }
        for (int i = 2; i <= N; i++) {
            for (int j = 0; j < i; j++) {
                ways[i] = (ways[i] + choose[i-1][j]) % M;
            }
        }
        long[][] dp = new long[(N+1)/2+1][N+1];
        dp[0][0] = 1;
        for (int i = 1; i <= (N+1)/2; i++) {
            for (int j = 1; j <= N; j++) {
                for (int k = 1; k <= j; k++) {
                    dp[i][j] = (dp[i][j] + ways[k] * choose[j][k] % M * dp[i-1][j-k] % M) % M;
                }
            }
        }
        long ans = 0;
        for (int i = 1; i <= (N+1)/2; i++) {
            ans = (ans + dp[i][N-(i-1)]) % M;
        }
        out.println(ans);
        out.close();
    }

    static StreamTokenizer in;
    static PrintWriter out;
    static BufferedReader br;

    static int nint() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    static void init_io() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        in = new StreamTokenizer(br);
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    }
}
// Problem: 1515_E. Phoenix and Computers
// Time complexity: cubic

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

public class CF1515E extends PrintWriter {
	CF1515E() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1515E o = new CF1515E(); o.main(); o.flush();
	}

	void main() {
		int n = sc.nextInt();
		int md = sc.nextInt();
		int k = (n + 1) / 2;
		int[][] dp = new int[k + 1][n + 1]; dp[0][0] = 1;
		for (int h = 1; h <= k; h++)
			for (int l = h; l <= n - h + 1; l++)
				dp[h][l] = (int) ((dp[h][l - 1] * 2L + dp[h - 1][l - 1]) * h % md);
		int ans = 0;
		for (int h = 1; h <= k; h++)
			ans = (ans + dp[h][n - h + 1]) % md;
		println(ans);
	}
}
// Problem: 1515_E. Phoenix and Computers
// Time complexity: cubic
// Main Code at the Bottom
import java.util.*;
import java.io.*; 
public class Main{
	//Fast IO class
    static class FastReader {
        BufferedReader br; 
        StringTokenizer st; 
        public FastReader() {
        	boolean env=System.getProperty("ONLINE_JUDGE") != null;
        	//env=true;
        	if(!env) {
        		try {
					br=new BufferedReader(new FileReader("src\\input.txt"));
				} catch (FileNotFoundException e) {
					e.printStackTrace();
				}
        	}
        	else br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) {
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
        int nextInt() {
            return Integer.parseInt(next()); 
        } 
        long nextLong() {
            return Long.parseLong(next()); 
        } 
        double nextDouble() {
            return Double.parseDouble(next()); 
        } 
        String nextLine() {
            String str = ""; 
            try {
                str = br.readLine(); 
            } 
            catch (IOException e) {
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }     
    static long MOD=(long)1e9+7;
    //debug
    static void debug(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
    static FastReader sc=new FastReader();
    static PrintWriter out=new PrintWriter(System.out);  
    //Global variables and functions
    static long memo[];
    static long C[][];
    static long exp(long a,long x) {
    	if(x==0) return 1;
    	if(x%2==0) return exp((a*a)%MOD,x/2)%MOD;
    	return ((a%MOD)*((exp((a*a)%MOD,x/2))%MOD))%MOD;
    }
    static void fill(int n) {
    	C = new long[n+1][n+1];
    	for(int i = 1; i<=n;i++) C[i][0]=C[i][i]=1;
    	for(int i=2;i<=n;i++) {
    		for(int j=1;j<=n;j++) {
    			C[i][j]=(C[i-1][j]+C[i-1][j-1])%MOD;
    		}
    	}
    }
    //Main function(The main code starts from here)
    public static void main (String[] args) throws java.lang.Exception {
    	int test=1;
    	//test=sc.nextInt();
    	while(test-->0) {
    		int n = sc.nextInt();
    		MOD = sc.nextLong();
    		memo = new long[n+1];
    		fill(n);
    		long dp[][] = new long[n+5][n+5];
    		for(int i=1;i<=n;i++) dp[i][i]=exp(2,i-1);
    		for(int i = 2; i <= n; i++) {
    			for(int j = 1; j < i; j++) {
    				for(int k = 1; k <= j; k++) {
    					long val = (dp[i-k-1][j-k]*C[j][k])%MOD;
    					if(memo[k-1] ==0) memo[k-1] = exp(2, k-1);
    					val=(val*memo[k-1])%MOD;
    					dp[i][j]=(dp[i][j]+val)%MOD;
    				}
    			}
    		}
    		long ans = 0;
    		for(int i=0;i<=n;i++) ans=(ans+dp[n][i])%MOD;
    		out.println(ans);
    	}
        out.flush();
        out.close();
    }
}
// Problem: 1515_E. Phoenix and Computers
// Time complexity: cubic
// practice with kaiboy, coached by rainboy
import java.io.*;
import java.util.*;

public class CF1515E extends PrintWriter {
	CF1515E() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1515E o = new CF1515E(); o.main(); o.flush();
	}

	void main() {
		int n = sc.nextInt();
		int md = sc.nextInt();
		int k = (n + 1) / 2;
		int[][] dp = new int[k + 1][n + 1]; dp[0][0] = 1;
		for (int h = 1; h <= k; h++)
			for (int l = h; l <= n - h + 1; l++)
				dp[h][l] = (int) ((dp[h][l - 1] * 2L + dp[h - 1][l - 1]) * h % md);
		int ans = 0;
		for (int h = 1; h <= k; h++)
			ans = (ans + dp[h][n - h + 1]) % md;
		println(ans);
	}
}
// Problem: 1515_E. Phoenix and Computers
// Time complexity: cubic
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class PhoenixAndComputers {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int mod = Integer.parseInt(st.nextToken());
        long[][] dp = new long[n+2][n+1];
        long[] pow = new long[n+1];
        pow[0] = 1;
        for (int i=1; i <= n; i++){
            pow[i] = pow[i-1]*2;
            pow[i] %= mod;
        }
        long[][] choose = new long[n*2+1][n+1];
        for (int i=0; i <= n; i++){
            choose[i][i] = 1;
        }
        for (int i=1; i <= n*2; i++){
            for (int j=0; j <= n; j++){
                choose[i][j] = choose[i-1][j];
                if (j > 0){
                    choose[i][j] += choose[i-1][j-1];
                }
                choose[i][j] %= mod;
            }
        }
        dp[0][0] = 1;
        for (int i=0; i < n; i++){ // number of computers on
            for (int j=0; j <= i; j++){ // number manually turned on
                for (int k=1; k+i <= n; k++){ // number of computers manually turned on in next "block"
                    dp[i+k+1][j+k] += (pow[k-1] * choose[j+k][k])%mod * dp[i][j];
                    dp[i+k+1][j+k] %= mod;
                }
            }
        }
        long ans = 0;
        for (int j=0; j <= n; j++){
            ans += dp[n+1][j];
            ans %= mod;
        }
        System.out.println(ans);
    }
}
// Problem: 1515_E. Phoenix and Computers
// Time complexity: cubic
import java.io.*;
import java.util.*;

public class CF1515E extends PrintWriter {
	CF1515E() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1515E o = new CF1515E(); o.main(); o.flush();
	}

	int[] ff, gg; int md;
	long ch(int n, int k) {
		return (long) ff[n] * gg[k] % md * gg[n - k] % md;
	}
	long inv(int a) {
		return a == 1 ? 1 : inv(a - md % a) * (md / a + 1) % md;
	}
	void main() {
		int n = sc.nextInt();
		md = sc.nextInt();
		int[] p2 = new int[n];
		for (int p = 1, i = 0; i < n; i++) {
			p2[i] = p;
			p = p * 2 % md;
		}
		ff = new int[n + 1];
		gg = new int[n + 1];
		long f = 1;
		for (int i = 0; i <= n; i++) {
			gg[i] = (int) inv(ff[i] = (int) f);
			f = f * (i + 1) % md;
		}
		int[][] dp = new int[n + 1][n + 1]; dp[1][1] = 1; dp[2][2] = 2;
		for (int u = 3; u <= n; u++)
			for (int v = 1; v <= u; v++) {
				long x = v == u ? p2[u - 1] : 0;
				for (int k = 1; k < v && k <= u - 2; k++)
					x += dp[u - k - 1][v - k] * ch(v, k) % md * p2[k - 1] % md;
				dp[u][v] = (int) (x % md);
			}
		int ans = 0;
		for (int v = 1; v <= n; v++)
			ans = (ans + dp[n][v]) % md;
		println(ans);
	}
}
// Problem: 1515_E. Phoenix and Computers
// Time complexity: cubic

import java.util.Arrays;
import java.util.Scanner;

public class e1515 {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);

        solve(s.nextInt(), s.nextLong());
    }


    public static long inv(long n, long mod) {
        if (n == 1) return 1;
        return (inv(mod % n, mod) * (mod - mod / n)) % mod;
    }

    public static void solve(int n, long mod) {
        long fact[] = new long[n + 2];
        long invFact[] = new long[n + 2];
        long twoPow[] = new long[n + 2];

        fact[0] = 1;
        invFact[0] = 1;
        twoPow[0] = 1;

        for (int i = 1; i < n + 2; i++) {
            fact[i] = (fact[i - 1] * i) % mod;
            invFact[i] = (invFact[i - 1] * inv(i, mod)) % mod;
            twoPow[i] = (2 * twoPow[i - 1]) % mod;
        }

        long dp[][] = new long[n + 2][];
        dp[0] = new long[]{1};

        long next[] = null;
        for (int i = 1; i <= n + 1; i++) {
            next = new long[i + 1];

            for (int j = 0; j < i - 1; j++) {
                for (int k = 0; k < dp[j].length; k++) {
                    next[k + i - j - 1] = (next[k + i - j - 1] + ((((dp[j][k] * twoPow[i - j - 2]) % mod * fact[k + i - j - 1]) % mod * invFact[k]) % mod * invFact[i - j - 1]) % mod) % mod;
                }
            }

            dp[i] = next;
        }

        long sum = 0;
        for (int i = 0; i < next.length; i++) {
            sum = (sum + next[i]) % mod;
        }

        System.out.println(sum);
    }
}
// Problem: 1515_E. Phoenix and Computers
// Time complexity: cubic
import java.awt.*;
import java.io.*;
import java.sql.Array;
import java.util.*;
import java.util.List;

public class Main {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(
                    new InputStreamReader(System.in));
        }

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

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

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

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

        String nextLine()
        {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    static final int N=405;
    static final int mod=1000000007;
    static final int INF=1000000009;
    static final int numBit=17;
    static FastReader r=new FastReader();
    static PrintWriter pw = new PrintWriter(System.out);

//    call dp[i][j] is number ways can turn on i computer but we just turn on j computer manually.
    static int [][]dp=new int[N][N];
    static int []p2=new int[N];
    static int []fac=new int[N];
    static int []ifac=new int[N];
    static int M;

    public static int mul(int a,int b){
        return (int)(1l*a*b%M);
    }

    public static int poww(int a,int b){
        int r=1;
        while(b>0){
            if(b%2==1) r=mul(r,a);
            a=mul(a,a);
            b>>=1;
        }
        return r;
    }

    public static int inv(int x){
        return poww(x,M-2);
    }

    public static int add(int a,int b){
        a+=b;
        if(a>=M) a-=M;
        return a;
    }

    public static int bino(int n,int k){
        return mul(fac[n],mul(ifac[n-k],ifac[k]));
    }

    public static void main(String[] args) throws IOException {
        int n=r.nextInt();
        M=r.nextInt();
        fac[0]=1;
        ifac[0]=1;
        p2[0]=1;
        for(int i=1;i<=n;++i){
            fac[i]=mul(fac[i-1],i);
            ifac[i]=inv(fac[i]);
            p2[i]=mul(p2[i-1],2);
        }
        int ans=0;
        dp[0][0]=1;
        for(int i=0;i<=n;++i){
            for(int k=0;k<=i;++k){
                for(int j=1;j<=n-i+1;++j){
                    dp[i+j+1][k+j]=add(dp[i+j+1][k+j],mul(dp[i][k],mul(p2[j-1],bino(j+k,j))));
                }
            }
        }
        for(int i=0;i<=n+1;++i){
            ans=add(ans,dp[n+1][i]);
        }
        pw.print(ans);
        pw.close();
    }
}