from sys import stdin def main(): NK = stdin.read().splitlines() players = ['you', 'grant'] points = {'you': 0, 'grant': 0} for i, s in enumerate(NK): n, k = map(int, s.split()) if i > 0 and n % k != 1: players[0], players[1] = players[1], players[0] if n % k == 1: points[players[0]] += 1 else: points[players[1]] += 1 print(points['you']) main()