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;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

// debug
template <class T> ostream& operator<<(ostream &s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
// *************** TEMPLATE END *************** 

int n, MOD;
int mod_pow(int x, int n) {
  if (n == 0) return 1;
  int tmp = mod_pow(x, n / 2);
  return tmp * tmp % MOD * (n % 2 ? x : 1) % MOD;
}

int inv(int x) {
  return mod_pow(x, MOD - 2);
}

vector<int> fact, fact_inv, pows;
void init() {
  fact = vector<int>(n + 1, 1);
  fact_inv = vector<int>(n + 1);
  REP (i, n) {
    fact[i + 1] = fact[i] * (i + 1) % MOD;
  }
  fact_inv[n] = inv(fact[n]);
  for (int i = n; i >= 1; i--) {
    fact_inv[i - 1] = fact_inv[i] * i % MOD;
  }
  REP (i, n + 1) {
    assert(fact[i] * fact_inv[i] % MOD == 1);
  }

  pows = vector<int>(n + 1, 1);
  REP (i, n) {
    pows[i + 1] = pows[i] * 2 % MOD;
  }
}
int comb(int n, int r) {
  return fact[n] * fact_inv[r] % MOD * fact_inv[n - r] % MOD;
}

signed main() {
  cin >> n >> MOD;
  int ans = 0;
  init();
  REPI (a, 1, n) {
    int b = n - a;
    int acc = 0;
    REPI (i, 1, b + 1) {
      int sign = (b - i) % 2 ? -1 : +1;
      acc += sign * comb(b, i) % MOD * mod_pow(pows[i] - 1, a) % MOD;
      (acc += MOD) %= MOD;
    }
    int tmp = (a * (a - 1) + b * (b - 1)) / 2 % MOD;
    ans += acc * comb(n, a) % MOD * mod_pow(2, tmp) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}

