F: Red-Black Soul Gem

problem

Homu-chan has the mysterious power to change the soul game to red or black, and to connect two different soul games with a magic thread. By using this power, Homu-chan can create a magic square by Sorujemu.

Homu-chan was wondering how many different magic squares there were when there were N numbered magic squares numbered from 1 to N, and the following conditions were met:

* You can only connect once between any of the two sources.
* All the colors of the game are either red or black.
* For any game, it is connected to at least one of the games whose color is different from its own.



At this time, the magic square can be regarded as a graph with the sorujemu as the apex and the magic thread as the side. Note that the graph does not have to be concatenated.

Homu-chan is not good at calculating, so let's create a fast program instead and calculate the number of different magic squares. However, the number is expected to be very large, so we will find the remainder after dividing by a prime number M.

Note that the magic squares G and H are different because the colors of G and H are different for a certain magic square v, or the pair u and v of a certain magic square is one of G and H. It means that it is connected only with.

Input format


N M

Constraint

* 2 \ leq N \ leq 2,000
* 10 ^ 8 \ leq M \ leq 10 ^ 9 + 7
* M is guaranteed to be prime



Output format

Divide the number of graphs that satisfy the condition by M and output the remainder as an integer on one line.

Input example 1


3 310779401

Output example 1


12

For example, the following magic squares meet the conditions.

Input example 2


7 566666561

Output example 2


98638848

For example, the following magic squares meet the conditions.

Input example 3


1010 1000000007

Output example 3


862232855

Note that we output the remainder after dividing by M.





Example

Input

3 310779401


Output

12
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int n,m;

ll bpow[2521];
ll comb[2521][2521];

ll modpow(ll a, ll b, ll m){
  ll r = 1;
  while(b){
    if(b&1)r=r*a%m;
    a=a*a%m;
    b>>=1;
  }
  return r;
}

int main(){
  scanf("%d%d",&n,&m);
  bpow[0] = 1; REP(i,n+1)bpow[i+1] = bpow[i]*2ll%m;
  comb[0][0] = 1;
  FOR(i,1,n+1)REP(j,i+1){
    if(j==0 || j==i)comb[i][j]=1;
    else comb[i][j] = (comb[i-1][j] + comb[i-1][j-1]) % m;
  }
  ll ans = 0;
  FOR(a,1,n){
    ll sum = 0;
    int B = n-a;
    FOR(b,1,B+1){
      ll add = 1;
      add *= modpow(bpow[b]-1, a, m); add %= m;
      ll mul = 1;
      if((B-b)%2==1)mul = m-1;
      mul = mul * comb[B][b] % m;
      sum += mul * add % m;
      sum %= m;
    }
    sum *= comb[n][a]; sum %= m;
    sum *= modpow(2ll, a*(a-1)/2, m); sum %= m;
    sum *= modpow(2ll, B*(B-1)/2, m); sum %= m;
    ans += sum; ans %= m;
  }
  printf("%lld\n",ans);
  return 0;
}

