def main(): import sys s = sys.stdin.readline().strip() n = len(s) if n == 0: print(-1) return # Precompute matching parentheses positions match = [0] * n stack = [] for i in range(n): if s[i] == '(': stack.append(i) else: if stack: j = stack.pop() match[j] = i match[i] = j # dp[i] will store the Grundy number for the substring starting at index i dp = [0] * (n + 1) for i in range(n - 1, -1, -1): if s[i] == '(': j = match[i] inner_grundy = dp[i + 1] rest_grundy = dp[j + 1] dp[i] = (inner_grundy + 1) ^ rest_grundy grundy = dp[0] if grundy != 0: print(0) else: print(1) if __name__ == '__main__': main()