// Arup Guha
// 7/16/2026
// Solution to UCF 1995 HS Contest Problem: Annoying Salesman

import java.util.*;

public class salesman {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);

		// Process, line by line - Java makes this easy.
		while (stdin.hasNext()) {
		
			// Houses are 2 to n.
			int n = stdin.nextInt();
			int k = stdin.nextInt();
			
			// Simulate it.
			int res = simulate(n, k);
			
			// Output result.
			System.out.println("The salesman visits "+res+" people before being caught.");
		}
	}
	
	// Simulate the process with n-1 houses and k as the house number for the police.
	public static int simulate(int n, int k) {
		
		// All the houses are there.
		TreeSet<Integer> set = new TreeSet<Integer>();
		for (int i=2; i<=n; i++) set.add(i);
			
		// Keep going.
		while (set.size() > 0) {
			
			// This will be my skip number.
			int skip = set.first();
				
			// Remove it.
			set.remove(skip);
			if (skip == k) return n - set.size() - 2;
				
			// Go to end of the houses.
			Integer cur = skip;
			while (cur != null) {
				
				// Houses to skip.
				for (int j=0; j<skip-1; j++) {
					cur = set.higher(cur);
					if (cur == null) break;
				}
				
				// We finished the list.
				if (cur == null) break;
					
				// Get to the one we are supposed to remove.
				cur = set.higher(cur);
				if (cur == null) break;
					
				// Remove it, if this is the one, we know our answer.
				set.remove(cur);
				if (cur == k) return n - set.size() - 2;
			}
		}
		
		// Should never get here.
		return n;
	}
}