ans = 0 first = True for i in range(1000): N, K = map(int, input().split()) first_win = (N - 1) % K != 1 ans += first and first_win if first_win: first = not first print(ans)