#include <stdio.h>

int lastRemaining(int n, int m) {
    int last = 0;
    int i;
    for (i = 2; i <= n; i++) {
        last = (last + m) % i;
    }
    return last + 1;
}

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    
    int result = lastRemaining(n, m);
    printf("%d\n", result);
    
    return 0;
}
