class NoListaC {

    int n;
    NoListaC next;

    NoListaC (int i) {
        this.n = i;
        this.next = null;
    }
}

class ListaC {

    NoListaC inicio;

    ListaC() {
        this.inicio = null; 
    }

    void criarLista(int n) {
        this.inicio = new NoListaC(1);
        NoListaC temp = this.inicio;
        NoListaC novo;
        for (int i = 1; i < n; i++) {
            novo = new NoListaC(i+1);
            temp.next = novo;
            temp = temp.next;
        }
        temp.next = this.inicio;
    }   

    NoListaC removerNos (int n, int k) {
        NoListaC temp = this.inicio;
        for (int i = 1; i < n; i++) {
            temp = temp.next;
        }
        temp.next = temp.next.next;         // Excluindo o primeiro nó
        n--;
        while (n > 1) {
            for (int j = 1; j < k; j++) {
                temp = temp.next;
            }
            temp.next = temp.next.next;     // Excluindo o nós restantes
            n--;
        }
        return temp;
    }

}

 public class QuestaoC {

    static void main (String[] Args) {
        Arquivo arq = new Arquivo("QuestaoC.in", "QuestaoC.out");
        ListaC lista = new ListaC();
        NoListaC restante;
        int n = arq.readInt();
        int k = arq.readInt();
        while ( n!=0 && k!=0 ) {
            lista.criarLista(n);  
            restante = lista.removerNos(n, k);
            arq.println(restante.n);
            n = arq.readInt();
            k = arq.readInt();
        }
        arq.close();
    }
}