#include<iostream>
using namespace std;
int main()
{
int n, m, c;
cin >> n >> m;
struct monkey{
int num;
monkey* next;
};
monkey *p = NULL,*mk = new monkey;
int i;
p = mk;
for (i = 1; i <= n; i ++){
p->next = new monkey;
p = p->next;
p->num = i;
}
p->next = mk->next;
monkey *t = p;//t 用来记录p的前驱
while (p->next != p){
c = 0;
p = t;
while (c != m){
c ++;
t = p;
p = p->next;
}
t->next = p->next;
delete p;
p = t->next;
}
cout << p->num << endl;
return 0;
}