number = 0# 0 -> first, 1 -> second count = 0 N,K = [],[] for i in range(1000): n,k = map(int,raw_input().split()) N.append(n) K.append(k) for i in range(1000): Fwin = False if N[i] % (K[i] + 1) != 1 and number == 0: count += 1 Fwin = True if N[i] % (K[i] + 1) == 1 and number == 1: count += 1 Fwin = True if Fwin: if(i + 1 < 1000):number = (1 if N[i + 1] % (K[i + 1] + 1) != 1 else 0) else: if(i + 1 < 1000):number = (0 if N[i + 1] % (K[i + 1] + 1) != 1 else 1) print count