public static void main(String[] args) {
// TODO Auto-generated method stub
int n = 9;
int m = 5;
fun(n, m);
}
//数学归纳
public static void fun(int n, int m){
if(n<0 || m<0){
System.out.println(-1);
return;
}
int s=0;
for(int i=2; i<=n; i++){
s = (s+m)%i;
}
System.out.println(s+1);
}
//模拟方法
public static void fun2(int n, int m){
LinkedList<Integer> list = new LinkedList<>();
for(int i=1; i<=n; i++){
list.add(i);
}
int idx=0;
while(list.size()>1){
int del = (idx+m-1)%list.size();
list.remove(del);
idx = del%list.size();
}
System.out.println(list.get(0));
}