import sys sys.setrecursionlimit(1000000000) # # Solution Template for Tennis Robot II # # Australian Informatics Olympiad 2024 # # This file is provided to assist with reading of input and writing of output # for the problem. You may modify this file however you wish, or # you may choose not to use this file at all. # # N is the number of bins. N = 0 # M is the number of instructions. M = 0 # X contains the number of balls in each bin. Note that this list starts from 1 # (not 0), and so the values are X[1] to X[N]. X = [] # A and B contain the instructions. Note that the lists start from 0, and so # the instructions are (A[0], B[0]) to (A[M-1], B[M-1]). A = [] B = [] # Read the values of N, M, X, A, and B. N, M = map(int, input().strip().split()) # Values in X are indexed from 1 to N (not 0 to N-1) X = [0] + list(map(int, input().strip().split())) for i in range(0, M): input_vars = list(map(int, input().strip().split())) A.append(input_vars[0]) B.append(input_vars[1]) # TODO: This is where you should compute your solution. Store the number of # instructions that the robot will successfully complete (or -1 if it will run # forever) into the variable answer. answer = 0 # Write the answer. if answer == -1: print("FOREVER") else: print(answer)