#include <iostream>

int main(int argc,char* argv[]){
  bool peeple[1001];

  while(true){
    int pop,space;
    std::cin >> pop >> space;
    if(pop == 0 && space == 0){break;}

    for(int i = 1; i <= pop; i++){
      peeple[i] = false;
    }
    
    int cur_pop = pop;
    int cur_num = 1;
    while(cur_pop != 1){
      int count = 0;
      while(count < (space-1) || peeple[cur_num] == true){
	if(peeple[cur_num] == true){
	  if(cur_num == pop){
	    cur_num = 1;
	  }else{
	    cur_num++;
	  }
	  continue;
	}else{
	  if(cur_num == pop){
	    cur_num = 1;
	  }else{
	    cur_num++;
	  }
	  count++;
	}
      }
      
      peeple[cur_num] = true;
      cur_pop--;
      while(peeple[cur_num] == true){
	if(cur_num == pop){
	  cur_num = 1;
	}else{
	  cur_num++;
	}
      }
    }
    
    for(int i = 1; i <= pop;i++){
      if(peeple[i] == false){
	std::cout << i << std::endl;
	break;
      }
    }
  }

  return 0;
  
}