#include <stdio.h>
int play(int n,int m)
{
    struct child {
        int name;
        child *p;};
 int i,j;
 child *first,*next,*pass;
 first=new child; // создание списка
  first->name=1;
  pass=first;
  for(i=2;i<=n;i++)
  {next=new child;
   next->name=i;
   pass->p=next;
   pass=next;
  }
pass->p=first;// замыкание круга
pass=first;
for(i=n;i>1; i--)
{ for (j=1;j<m;j++)
{
    next=pass;
pass=pass->p;
}
printf("%2d\n",pass->name);
next->p=pass->p;
delete(pass);
pass=next->p;
} return pass->name;// Возврат результата
}


int main()
{ int kolplay,schit;
    puts("input number of players and chislo schitalki");
    scanf("%d %d",&kolplay,&schit);
    printf("Result= %4d\n",play(kolplay,schit));
    return 0;
}
