#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        if(n==0&&m==0)break;
        vector<int> member;
        int temp;
        rep(i,n)
        {

            member.push_back(i+1);
        }
        vector<int>::iterator it = member.begin();

        rep(i,n-1)
        {
            rep(j,m-1)
            {
                ++it;
                if(it==member.end())it = member.begin();
            }
            member.erase(it);
            if(it==member.end())it = member.begin();
        }
        cout << member[0]<< endl;
    }

    return 0;
}