//verify AOJ1275
#include<iostream>
#include<ctime>
#include<map>
using namespace std;

unsigned int xor128(){
	static unsigned int x=123456789,y=362436069,z=521288629,w=88675123; 
	unsigned int t=(x^(x<<11));
	x=y;y=z;z=w;
	return w=(w^(w>>19))^(t^(t>>8));
}


class Nothing{};

template<class Key,class Val=Nothing>
class Treap{
	struct Node{
		unsigned int priority;
		Key key;
		Val value;
		Node *left,*right;
		int size;
		Node(const Key& k,const Val& v)
			:priority(xor128()),key(k),value(v),left(0),right(0),size(1){}
		~Node(){
			if(left)delete left;
			if(right)delete right;
		}
		Node *rotate_right(){
			Node *s=left;
			left=s->right;
			s->right=this;
			return s;
		}
		Node *rotate_left(){
			Node *s=right;
			right=s->left;
			s->left=this;
			return s;
		}
		Node *merge(Node *t){
			if(!this)return t;
			if(!t)return this;
			Node *s=this;
			if(t->key < key){
				left = left->merge(t);
				if(priority < left->priority)s=rotate_right();
			}else if(key < t->key){
				right = right->merge(t);
				if(priority < right->priority)s=rotate_left();
			}else return this;
			s->update();
			return s;
		}
		Node *find(const Key& k){
			return !this?NULL:k==key?
				this:k<key?left->find(k):right->find(k);
		}
		Node *erase(const Key& k){
			if(!this)return NULL;
			Node *s=this;
			if(k==key){
				if(!left&&!right){
					delete this;
					return NULL;
				}
				if(left && (!right || left->priority > right->priority)){
					s=rotate_right();
					s->right=s->right->erase(k);
				}else{
					s=rotate_left();
					s->left=s->left->erase(k);
				}
			}
			else if(k<key)left = left->erase(k);
			else right = right->erase(k);
			s->update();
			return s;
		}
		Node *nth_element(int n){
			if(size<=n)return NULL;
			Node *t=this;
			while((t->left?t->left->size:0)!=n){
				if(t->left && n<=t->left->size){
					t=t->left;
				}else {
					if(t->left)n-=t->left->size;
					n--;
					t=t->right;
				}
			}
			return t;
		}
		int rank_gt(const Key& k)const{
			if(!this)return 0;
			if(k==key){
				return right?right->size:0;
			}else if(k<key){
				return 1 + (right?right->size:0) + left->rank_gt(k);
			}else{
				return right->rank_gt(k);
			}
		}
		void update(){
			left->update_size();
			right->update_size();
			update_size();
		}
		void update_size(){
			if(!this)return;
			size = 1 + (left?left->size:0) + (right?right->size:0);
		}
	} *root;
public:
	Treap():root(0){}
	~Treap(){if(root)delete root;}
	void insert(const Key& k,const Val& v=Nothing()){
		root=root->merge(new Node(k,v));
	}
	void merge(Treap &t){//区間が重なっていると使えない
		root=root->merge(t->root);
		t->root=0;
	}
	void split(const Key& k){
	}
	Val* find(const Key& k){
		Node *p=root->find(k);
		if(p)return &p->value;
		return NULL;
	}
	void erase(const Key& k){
		root=root->erase(k);
	}
	Key nth_element(int n)const{
		return root->nth_element(n)->key;
	}
	int rank_gt(const Key& k)const{
		return root->rank_gt(k);
	}
	int size()const{
		return root->size;
	}
};

int main(){
	int n,m;
	while(cin>>n>>m,n|m){
		Treap<int> treap;
		int v=n-1;
		for(int i=0;i<n;i++)treap.insert(i);
		for(int i=0;i<n-1;i++){
			int mm=m%(n-i),gt=treap.rank_gt(v);
			v=treap.nth_element( (n-i-gt+mm-1+n-i)%(n-i) );
			treap.erase(v);
		}
		cout<<treap.nth_element(0)+1<<endl;
	}
	return 0;
}