import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; public class Main { public static Scanner sc = new Scanner(System.in); public static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws Exception { int n = sc.nextInt(); int m = sc.nextInt(); // System.out.println(f(n, m) + 1); System.out.println(josephusKill(n, m)); } static int josephusKill(int n, int m){ if (n == 1) { return 1; } int last = 0; for (int i = 2; i <= n; ++i){ last = (last + m) % i; } return last + 1; } static int f(int n, int m){ if(n == 1){ return 0; } return (f(n-1, m) + m) % n; } }