#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (n); i++)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, K;
    cin >> n >> K;
    int ok = 1e18, ng = 0;
    auto check = [&](int m) {
        int cur = m;
        REP(i, n) {
            if (cur == 0) return false;
            cur -= (cur + K - 1) / K;
        }
        return true;
    };
    while (abs(ok - ng) > 1) {
        int m = (ok + ng) / 2;
        (check(m) ? ok : ng) = m;
    }

    cout << ok - 1 << endl;
}

