n, q = list(map(int, input().split())) xex = 0 for i in range(q): l, r = list(map(int, input().split())) x = (pow(2, (r)) - pow(2, (l-1))) print(bin(x:=x^xex).count("1")) xex = x