#include <bits/stdc++.h>
using namespace std;
queue <int> a;
int main()
{
int n, m, cnt;
cin >> n >> m;
for(int i = 0; i < n; i++)
{
a.push(i);
}
while(!a.empty())
{
if(cnt == m)
{
cout << a.front() << " ";
a.pop();
cnt = 1;
}
else if(cnt != m)
{
cnt++;
a.push(a.front());
a.pop();
}
}
return 0;
}