#include <stdio.h> int main() { int n, m, ans, i, j = 0, x; scanf("%d%d", &n, &m); i = n; ans = n; x = n; while(i >= m) { x = i / m; j = i % x; i = x + j; ans = ans + x; } printf("%d\n", ans); return 0; }