#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<cctype>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
using namespace std;
long long pw(int a, int b) {
long long s = 1;
while (b) {
if (b & 1)s = s * a;
a = a * a;
b >>= 1;
}
return s;
}
long long C(int r, int k) {
if (r < k)return 0;
long long s = 1;
for (int i = r; i > r - k; i--) {
s *= i;
s /= (r - i + 1);
}
return s;
}
int main() {
int n, r;
cin >> n >> r;
long long ans = 0;
for (int k = 0; k <= r - 1; k++) {
ans += ((k & 1 ? -1 : 1) * C(r, k) * pw(r - k, n));
}
cout << ans;
}