#include<algorithm>
#include<cstring>
#include<cstdio>
#include<iostream>
typedef long long ll;
using std::min;
const int N = 5000 + 15;
int n,m;
ll p;
ll dp[N][N], sum[N][N];
int main() {
scanf("%d %d %d", &n, &m, &p);
dp[0][0] = 1;
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= min(i, m - 1); j ++) {
(dp[i][j] += dp[i - 1][j - 1] * (m - (j - 1)) % p) %= p;
(dp[i][j] += sum[i - 1][j]) %= p;
}
for(int j = m - 1; j >= 1; j --)
sum[i][j] = (sum[i][j + 1] + dp[i][j]) % p;
}
ll ans = 0;
for (int i = 1; i < m; i ++) (ans += dp[n][i]) %= p;
printf("%lld
", ans);
return 0;
}