#include<stdio.h>
#include<stdlib.h>
typedef struct st{
int data;
struct st*next;
} st;
st*cl(int n)
{ st*l=(st*)malloc(sizeof(st));
st*r=l;
int i=2;
st*s=(st*)malloc(sizeof(st));
s->data=0;
r->next=s;
r=s;
while(n-->1)
{ st*s=(st*)malloc(sizeof(st));
s->data=i++;
r->next=s;
r=s;
}
r->next=l;
l->data=1;
}
void del(st*l,st*r)
{
st*p=r;
p=p->next;
printf("%d ",p->data);
r->next=p->next;
p=NULL;
free(p);
}
int main(void)
{
int n,j,k;scanf("%d %d",&n,&k);
st*l=cl(n);
st*r=l,*p=l;
p=p->next;
r->next=p->next;
p=NULL;
free(p);
while(r->next!=r)
{ for(j=1;j<=k-2;j++)
r=r->next;
del(l,r);
r=r->next;
}
printf("%d",r->data);
}