#include <stdio.h>
#include <stdlib.h>

typedef int Item;

struct no { Item item; struct no *prox; };

main(int argc, char *argv[]) {
  int i, N, M; 
  struct no *t = malloc(sizeof(struct no)), *x = t;

  scanf("%d %d", &N, &M); 
  t->item = 1; t->prox = t;
  for (i=2; i<=N; i++) {
    x->prox = malloc(sizeof(struct no));
    x = x->prox;
    x->item = i; x->prox = t;
  }
  while (x != x->prox) {
    for (i=1; i<M; i++) x = x->prox;
    x->prox = x->prox->prox; /* versão simplificada, que não libera memória */
  }
  printf("lider: %d\n", x->item);
}
