#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <bitset>
 
#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	int n, m;
	std::vector<bool> members;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	while(ifs >> n >> m){
#else
	while(std::cin >> n >> m){
#endif
		if(n == 0 && m == 0){ break; }
		members.clear();
		members.resize(n, true);

		int i = 0, mm = m;
		for(;;){
			int rcounter = 0;
			for(int j = 0; j < members.size(); j++){
				if(members[j]){
					rcounter++;
				}
			}
			if(rcounter == 1){
				int winner = 0;
				for(int j = 0; j < members.size(); j++){
					if(members[j]){
						winner = j + 1;
						break;
					}
				}
				std::cout << winner << std::endl;
				break;
			}
			
			mm = m - 1;
			while(mm >= 1){
				if(members[i]){
					mm--;
				}
				i++;
				if(i == members.size()){
					i = 0;
				}
			}
			while(!members[i]){
				i++;
				if(i == members.size()){
					i = 0;
				}
			}
			members[i] = false;
		}
	}


 
#if INPUT_FROM_FILE
	//fclose(fp);
#endif
    return 0;
}
